Esempio n. 1
0
        private void ScanJSXWord()
        {
            var ch = _text[_pos];

            while (IdentifierHelper.IsIdentifierChar(ch, false) || ch == '-')
            {
                ch = _text[++_pos];
            }
            this.FinishToken(TokenType.JSXName);
        }
Esempio n. 2
0
        public virtual void ScanToken()
        {
            var ch = _text[_pos];

            if (IdentifierHelper.IsIdentifierStart(ch, _ecmaVersion >= 6) || ch == '\\' /* '\' */)
            {
                this.ScanWord();
                return;
            }
            this.ScanTokenFromChar(ch);
        }
Esempio n. 3
0
        protected string ScanEscapedWord()
        {
            _containsEsc = false;
            var astral     = _ecmaVersion >= 6;
            var chunkStart = _pos;
            var first      = true;
            var word       = new StringBuilder();

            while (_pos < _text.Length)
            {
                var ch = _text[_pos];
                if (IdentifierHelper.IsIdentifierChar(ch, astral))
                {
                    _pos += ch <= 0xffff ? 1 : 2;
                }
                else if (ch == '\\')
                {
                    _containsEsc = true;
                    word.Append(new string(_text, chunkStart, _pos));
                    var escStart = _pos;
                    if (_text[++_pos] != 'u')
                    {
                        this.Raise("Expecting Unicode escape sequence \\uXXXX");
                    }
                    var esc   = this.ScanCodePoint();
                    var valid = first ?
                                IdentifierHelper.IsIdentifierStart((char)esc, astral) :
                                IdentifierHelper.IsIdentifierChar((char)esc, astral);
                    if (!valid)
                    {
                        this.Raise("Invalid Unicode escape");
                    }
                    word.Append(this.CodePointToString(esc));
                    chunkStart = _pos;
                }
                else
                {
                    break;
                }
            }
            return(word.Append(new string(_text, chunkStart, _pos - chunkStart)).ToString());
        }
Esempio n. 4
0
        public override void ScanToken()
        {
            var context = this.CurrentContext();

            if (context == TokenContext.JSXExpr)
            {
                this.ScanJSXToken();
                return;
            }
            var ch = _text[_pos];

            if (context == TokenContext.JSXOpenTag || context == TokenContext.JSXCloseTag)
            {
                if (IdentifierHelper.IsIdentifierStart(ch, false))
                {
                    this.ScanJSXWord();
                    return;
                }
                if (ch == '>')
                {
                    _pos++;
                    this.FinishToken(TokenType.JSXTagEnd);
                    return;
                }

                if ((ch == '\'' || ch == '"') && context == TokenContext.JSXOpenTag)
                {
                    this.ScanJSXString(ch);
                    return;
                }
            }
            if (ch == '<' && _exprAllowed)
            {
                _pos++;
                this.FinishToken(TokenType.JSXTagStart);
                return;
            }
            base.ScanToken();
        }