(code, options)
| 3582 | } |
| 3583 | |
| 3584 | function tokenize(code, options) { |
| 3585 | var toString, |
| 3586 | token, |
| 3587 | tokens; |
| 3588 | |
| 3589 | toString = String; |
| 3590 | if (typeof code !== 'string' && !(code instanceof String)) { |
| 3591 | code = toString(code); |
| 3592 | } |
| 3593 | |
| 3594 | delegate = SyntaxTreeDelegate; |
| 3595 | source = code; |
| 3596 | index = 0; |
| 3597 | lineNumber = (source.length > 0) ? 1 : 0; |
| 3598 | lineStart = 0; |
| 3599 | length = source.length; |
| 3600 | lookahead = null; |
| 3601 | state = { |
| 3602 | allowIn: true, |
| 3603 | labelSet: {}, |
| 3604 | inFunctionBody: false, |
| 3605 | inIteration: false, |
| 3606 | inSwitch: false, |
| 3607 | lastCommentStart: -1 |
| 3608 | }; |
| 3609 | |
| 3610 | extra = {}; |
| 3611 | |
| 3612 | // Options matching. |
| 3613 | options = options || {}; |
| 3614 | |
| 3615 | // Of course we collect tokens here. |
| 3616 | options.tokens = true; |
| 3617 | extra.tokens = []; |
| 3618 | extra.tokenize = true; |
| 3619 | // The following two fields are necessary to compute the Regex tokens. |
| 3620 | extra.openParenToken = -1; |
| 3621 | extra.openCurlyToken = -1; |
| 3622 | |
| 3623 | extra.range = (typeof options.range === 'boolean') && options.range; |
| 3624 | extra.loc = (typeof options.loc === 'boolean') && options.loc; |
| 3625 | |
| 3626 | if (typeof options.comment === 'boolean' && options.comment) { |
| 3627 | extra.comments = []; |
| 3628 | } |
| 3629 | if (typeof options.tolerant === 'boolean' && options.tolerant) { |
| 3630 | extra.errors = []; |
| 3631 | } |
| 3632 | |
| 3633 | try { |
| 3634 | peek(); |
| 3635 | if (lookahead.type === Token.EOF) { |
| 3636 | return extra.tokens; |
| 3637 | } |
| 3638 | |
| 3639 | token = lex(); |
| 3640 | while (lookahead.type !== Token.EOF) { |
| 3641 | try { |
nothing calls this directly
no test coverage detected