"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _index = require('../../tokenizer/index'); var _types = require('../../tokenizer/types'); var _base = require('../../traverser/base'); var _expression = require('../../traverser/expression'); var _util = require('../../traverser/util'); var _charcodes = require('../../util/charcodes'); var _identifier = require('../../util/identifier'); var _typescript = require('../typescript'); // Reads inline JSX contents token. function jsxReadToken() { for (;;) { if (_base.state.pos >= _base.input.length) { _util.unexpected.call(void 0, "Unterminated JSX contents"); return; } const ch = _base.input.charCodeAt(_base.state.pos); switch (ch) { case _charcodes.charCodes.lessThan: case _charcodes.charCodes.leftCurlyBrace: if (_base.state.pos === _base.state.start) { if (ch === _charcodes.charCodes.lessThan) { _base.state.pos++; _index.finishToken.call(void 0, _types.TokenType.jsxTagStart); return; } _index.getTokenFromCode.call(void 0, ch); return; } _index.finishToken.call(void 0, _types.TokenType.jsxText); return; default: _base.state.pos++; } } } function jsxReadString(quote) { _base.state.pos++; for (;;) { if (_base.state.pos >= _base.input.length) { _util.unexpected.call(void 0, "Unterminated string constant"); return; } const ch = _base.input.charCodeAt(_base.state.pos); if (ch === quote) { _base.state.pos++; break; } _base.state.pos++; } _index.finishToken.call(void 0, _types.TokenType.string); } // Read a JSX identifier (valid tag or attribute name). // // Optimized version since JSX identifiers can't contain // escape characters and so can be read as single slice. // Also assumes that first character was already checked // by isIdentifierStart in readToken. function jsxReadWord() { let ch; do { if (_base.state.pos > _base.input.length) { _util.unexpected.call(void 0, "Unexpectedly reached the end of input."); return; } ch = _base.input.charCodeAt(++_base.state.pos); } while (_identifier.IS_IDENTIFIER_CHAR[ch] || ch === _charcodes.charCodes.dash); _index.finishToken.call(void 0, _types.TokenType.jsxName); } // Parse next token as JSX identifier function jsxParseIdentifier() { nextJSXTagToken(); } // Parse namespaced identifier. function jsxParseNamespacedName(identifierRole) { jsxParseIdentifier(); if (!_index.eat.call(void 0, _types.TokenType.colon)) { // Plain identifier, so this is an access. _base.state.tokens[_base.state.tokens.length - 1].identifierRole = identifierRole; return; } // Process the second half of the namespaced name. jsxParseIdentifier(); } // Parses element name in any form - namespaced, member // or single identifier. function jsxParseElementName() { jsxParseNamespacedName(_index.IdentifierRole.Access); while (_index.match.call(void 0, _types.TokenType.dot)) { nextJSXTagToken(); jsxParseIdentifier(); } } // Parses any type of JSX attribute value. function jsxParseAttributeValue() { switch (_base.state.type) { case _types.TokenType.braceL: _index.next.call(void 0, ); jsxParseExpressionContainer(); nextJSXTagToken(); return; case _types.TokenType.jsxTagStart: jsxParseElement(); nextJSXTagToken(); return; case _types.TokenType.string: nextJSXTagToken(); return; default: _util.unexpected.call(void 0, "JSX value should be either an expression or a quoted JSX text"); } } function jsxParseEmptyExpression() { // Do nothing. } // Parse JSX spread child, after already processing the { // Does not parse the closing } function jsxParseSpreadChild() { _util.expect.call(void 0, _types.TokenType.ellipsis); _expression.parseExpression.call(void 0, ); } // Parses JSX expression enclosed into curly brackets, after already processing the { // Does not parse the closing } function jsxParseExpressionContainer() { if (_index.match.call(void 0, _types.TokenType.braceR)) { jsxParseEmptyExpression(); } else { _expression.parseExpression.call(void 0, ); } } // Parses following JSX attribute name-value pair. function jsxParseAttribute() { if (_index.eat.call(void 0, _types.TokenType.braceL)) { _util.expect.call(void 0, _types.TokenType.ellipsis); _expression.parseMaybeAssign.call(void 0, ); // } nextJSXTagToken(); return; } jsxParseNamespacedName(_index.IdentifierRole.ObjectKey); if (_index.match.call(void 0, _types.TokenType.eq)) { nextJSXTagToken(); jsxParseAttributeValue(); } } // Parses JSX opening tag starting after "<". // Returns true if the tag was self-closing. // Does not parse the last token. function jsxParseOpeningElement() { if (_index.match.call(void 0, _types.TokenType.jsxTagEnd)) { // This is an open-fragment. return false; } jsxParseElementName(); if (_base.isTypeScriptEnabled) { _typescript.tsTryParseJSXTypeArgument.call(void 0, ); } while (!_index.match.call(void 0, _types.TokenType.slash) && !_index.match.call(void 0, _types.TokenType.jsxTagEnd) && !_base.state.error) { jsxParseAttribute(); } const isSelfClosing = _index.match.call(void 0, _types.TokenType.slash); if (isSelfClosing) { // / nextJSXTagToken(); } return isSelfClosing; } // Parses JSX closing tag starting after "