diff options
Diffstat (limited to 'node_modules/babylon/lib/plugins')
-rw-r--r-- | node_modules/babylon/lib/plugins/flow.js | 1235 | ||||
-rw-r--r-- | node_modules/babylon/lib/plugins/jsx/index.js | 482 | ||||
-rw-r--r-- | node_modules/babylon/lib/plugins/jsx/xhtml.js | 258 |
3 files changed, 1975 insertions, 0 deletions
diff --git a/node_modules/babylon/lib/plugins/flow.js b/node_modules/babylon/lib/plugins/flow.js new file mode 100644 index 000000000..9f38c043c --- /dev/null +++ b/node_modules/babylon/lib/plugins/flow.js @@ -0,0 +1,1235 @@ +"use strict"; + +exports.__esModule = true; + +exports.default = function (instance) { + // plain function return types: function name(): string {} + instance.extend("parseFunctionBody", function (inner) { + return function (node, allowExpression) { + if (this.match(_types.types.colon) && !allowExpression) { + // if allowExpression is true then we're parsing an arrow function and if + // there's a return type then it's been handled elsewhere + node.returnType = this.flowParseTypeAnnotation(); + } + + return inner.call(this, node, allowExpression); + }; + }); + + // interfaces + instance.extend("parseStatement", function (inner) { + return function (declaration, topLevel) { + // strict mode handling of `interface` since it's a reserved word + if (this.state.strict && this.match(_types.types.name) && this.state.value === "interface") { + var node = this.startNode(); + this.next(); + return this.flowParseInterface(node); + } else { + return inner.call(this, declaration, topLevel); + } + }; + }); + + // declares, interfaces and type aliases + instance.extend("parseExpressionStatement", function (inner) { + return function (node, expr) { + if (expr.type === "Identifier") { + if (expr.name === "declare") { + if (this.match(_types.types._class) || this.match(_types.types.name) || this.match(_types.types._function) || this.match(_types.types._var)) { + return this.flowParseDeclare(node); + } + } else if (this.match(_types.types.name)) { + if (expr.name === "interface") { + return this.flowParseInterface(node); + } else if (expr.name === "type") { + return this.flowParseTypeAlias(node); + } + } + } + + return inner.call(this, node, expr); + }; + }); + + // export type + instance.extend("shouldParseExportDeclaration", function (inner) { + return function () { + return this.isContextual("type") || this.isContextual("interface") || inner.call(this); + }; + }); + + instance.extend("parseConditional", function (inner) { + return function (expr, noIn, startPos, startLoc, refNeedsArrowPos) { + // only do the expensive clone if there is a question mark + // and if we come from inside parens + if (refNeedsArrowPos && this.match(_types.types.question)) { + var state = this.state.clone(); + try { + return inner.call(this, expr, noIn, startPos, startLoc); + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + refNeedsArrowPos.start = err.pos || this.state.start; + return expr; + } else { + throw err; + } + } + } + + return inner.call(this, expr, noIn, startPos, startLoc); + }; + }); + + instance.extend("parseParenItem", function (inner) { + return function (node, startLoc, startPos) { + node = inner.call(this, node, startLoc, startPos); + if (this.eat(_types.types.question)) { + node.optional = true; + } + + if (this.match(_types.types.colon)) { + var typeCastNode = this.startNodeAt(startLoc, startPos); + typeCastNode.expression = node; + typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); + + return this.finishNode(typeCastNode, "TypeCastExpression"); + } + + return node; + }; + }); + + instance.extend("parseExport", function (inner) { + return function (node) { + node = inner.call(this, node); + if (node.type === "ExportNamedDeclaration") { + node.exportKind = node.exportKind || "value"; + } + return node; + }; + }); + + instance.extend("parseExportDeclaration", function (inner) { + return function (node) { + if (this.isContextual("type")) { + node.exportKind = "type"; + + var declarationNode = this.startNode(); + this.next(); + + if (this.match(_types.types.braceL)) { + // export type { foo, bar }; + node.specifiers = this.parseExportSpecifiers(); + this.parseExportFrom(node); + return null; + } else { + // export type Foo = Bar; + return this.flowParseTypeAlias(declarationNode); + } + } else if (this.isContextual("interface")) { + node.exportKind = "type"; + var _declarationNode = this.startNode(); + this.next(); + return this.flowParseInterface(_declarationNode); + } else { + return inner.call(this, node); + } + }; + }); + + instance.extend("parseClassId", function (inner) { + return function (node) { + inner.apply(this, arguments); + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + }; + }); + + // don't consider `void` to be a keyword as then it'll use the void token type + // and set startExpr + instance.extend("isKeyword", function (inner) { + return function (name) { + if (this.state.inType && name === "void") { + return false; + } else { + return inner.call(this, name); + } + }; + }); + + // ensure that inside flow types, we bypass the jsx parser plugin + instance.extend("readToken", function (inner) { + return function (code) { + if (this.state.inType && (code === 62 || code === 60)) { + return this.finishOp(_types.types.relational, 1); + } else { + return inner.call(this, code); + } + }; + }); + + // don't lex any token as a jsx one inside a flow type + instance.extend("jsx_readToken", function (inner) { + return function () { + if (!this.state.inType) return inner.call(this); + }; + }); + + instance.extend("toAssignable", function (inner) { + return function (node, isBinding, contextDescription) { + if (node.type === "TypeCastExpression") { + return inner.call(this, this.typeCastToParameter(node), isBinding, contextDescription); + } else { + return inner.call(this, node, isBinding, contextDescription); + } + }; + }); + + // turn type casts that we found in function parameter head into type annotated params + instance.extend("toAssignableList", function (inner) { + return function (exprList, isBinding, contextDescription) { + for (var i = 0; i < exprList.length; i++) { + var expr = exprList[i]; + if (expr && expr.type === "TypeCastExpression") { + exprList[i] = this.typeCastToParameter(expr); + } + } + return inner.call(this, exprList, isBinding, contextDescription); + }; + }); + + // this is a list of nodes, from something like a call expression, we need to filter the + // type casts that we've found that are illegal in this context + instance.extend("toReferencedList", function () { + return function (exprList) { + for (var i = 0; i < exprList.length; i++) { + var expr = exprList[i]; + if (expr && expr._exprListItem && expr.type === "TypeCastExpression") { + this.raise(expr.start, "Unexpected type cast"); + } + } + + return exprList; + }; + }); + + // parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents + // the position where this function is called + instance.extend("parseExprListItem", function (inner) { + return function (allowEmpty, refShorthandDefaultPos) { + var container = this.startNode(); + var node = inner.call(this, allowEmpty, refShorthandDefaultPos); + if (this.match(_types.types.colon)) { + container._exprListItem = true; + container.expression = node; + container.typeAnnotation = this.flowParseTypeAnnotation(); + return this.finishNode(container, "TypeCastExpression"); + } else { + return node; + } + }; + }); + + instance.extend("checkLVal", function (inner) { + return function (node) { + if (node.type !== "TypeCastExpression") { + return inner.apply(this, arguments); + } + }; + }); + + // parse class property type annotations + instance.extend("parseClassProperty", function (inner) { + return function (node) { + if (this.match(_types.types.colon)) { + node.typeAnnotation = this.flowParseTypeAnnotation(); + } + return inner.call(this, node); + }; + }); + + // determine whether or not we're currently in the position where a class property would appear + instance.extend("isClassProperty", function (inner) { + return function () { + return this.match(_types.types.colon) || inner.call(this); + }; + }); + + // parse type parameters for class methods + instance.extend("parseClassMethod", function () { + return function (classBody, method, isGenerator, isAsync) { + if (this.isRelational("<")) { + method.typeParameters = this.flowParseTypeParameterDeclaration(); + } + this.parseMethod(method, isGenerator, isAsync); + classBody.body.push(this.finishNode(method, "ClassMethod")); + }; + }); + + // parse a the super class type parameters and implements + instance.extend("parseClassSuper", function (inner) { + return function (node, isStatement) { + inner.call(this, node, isStatement); + if (node.superClass && this.isRelational("<")) { + node.superTypeParameters = this.flowParseTypeParameterInstantiation(); + } + if (this.isContextual("implements")) { + this.next(); + var implemented = node.implements = []; + do { + var _node = this.startNode(); + _node.id = this.parseIdentifier(); + if (this.isRelational("<")) { + _node.typeParameters = this.flowParseTypeParameterInstantiation(); + } else { + _node.typeParameters = null; + } + implemented.push(this.finishNode(_node, "ClassImplements")); + } while (this.eat(_types.types.comma)); + } + }; + }); + + // parse type parameters for object method shorthand + instance.extend("parseObjPropValue", function (inner) { + return function (prop) { + var typeParameters = void 0; + + // method shorthand + if (this.isRelational("<")) { + typeParameters = this.flowParseTypeParameterDeclaration(); + if (!this.match(_types.types.parenL)) this.unexpected(); + } + + inner.apply(this, arguments); + + // add typeParameters if we found them + if (typeParameters) { + (prop.value || prop).typeParameters = typeParameters; + } + }; + }); + + instance.extend("parseAssignableListItemTypes", function () { + return function (param) { + if (this.eat(_types.types.question)) { + param.optional = true; + } + if (this.match(_types.types.colon)) { + param.typeAnnotation = this.flowParseTypeAnnotation(); + } + this.finishNode(param, param.type); + return param; + }; + }); + + instance.extend("parseMaybeDefault", function (inner) { + return function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var node = inner.apply(this, args); + + if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) { + this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`"); + } + + return node; + }; + }); + + // parse typeof and type imports + instance.extend("parseImportSpecifiers", function (inner) { + return function (node) { + node.importKind = "value"; + + var kind = null; + if (this.match(_types.types._typeof)) { + kind = "typeof"; + } else if (this.isContextual("type")) { + kind = "type"; + } + if (kind) { + var lh = this.lookahead(); + if (lh.type === _types.types.name && lh.value !== "from" || lh.type === _types.types.braceL || lh.type === _types.types.star) { + this.next(); + node.importKind = kind; + } + } + + inner.call(this, node); + }; + }); + + // parse function type parameters - function foo<T>() {} + instance.extend("parseFunctionParams", function (inner) { + return function (node) { + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + inner.call(this, node); + }; + }); + + // parse flow type annotations on variable declarator heads - let foo: string = bar + instance.extend("parseVarHead", function (inner) { + return function (decl) { + inner.call(this, decl); + if (this.match(_types.types.colon)) { + decl.id.typeAnnotation = this.flowParseTypeAnnotation(); + this.finishNode(decl.id, decl.id.type); + } + }; + }); + + // parse the return type of an async arrow function - let foo = (async (): number => {}); + instance.extend("parseAsyncArrowFromCallExpression", function (inner) { + return function (node, call) { + if (this.match(_types.types.colon)) { + node.returnType = this.flowParseTypeAnnotation(); + } + + return inner.call(this, node, call); + }; + }); + + // todo description + instance.extend("shouldParseAsyncArrow", function (inner) { + return function () { + return this.match(_types.types.colon) || inner.call(this); + }; + }); + + // We need to support type parameter declarations for arrow functions. This + // is tricky. There are three situations we need to handle + // + // 1. This is either JSX or an arrow function. We'll try JSX first. If that + // fails, we'll try an arrow function. If that fails, we'll throw the JSX + // error. + // 2. This is an arrow function. We'll parse the type parameter declaration, + // parse the rest, make sure the rest is an arrow function, and go from + // there + // 3. This is neither. Just call the inner function + instance.extend("parseMaybeAssign", function (inner) { + return function () { + var jsxError = null; + + for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + if (_types.types.jsxTagStart && this.match(_types.types.jsxTagStart)) { + var state = this.state.clone(); + try { + return inner.apply(this, args); + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + jsxError = err; + } else { + throw err; + } + } + } + + // Need to push something onto the context to stop + // the JSX plugin from messing with the tokens + this.state.context.push(_context.types.parenExpression); + if (jsxError != null || this.isRelational("<")) { + var arrowExpression = void 0; + var typeParameters = void 0; + try { + typeParameters = this.flowParseTypeParameterDeclaration(); + + arrowExpression = inner.apply(this, args); + arrowExpression.typeParameters = typeParameters; + arrowExpression.start = typeParameters.start; + arrowExpression.loc.start = typeParameters.loc.start; + } catch (err) { + throw jsxError || err; + } + + if (arrowExpression.type === "ArrowFunctionExpression") { + return arrowExpression; + } else if (jsxError != null) { + throw jsxError; + } else { + this.raise(typeParameters.start, "Expected an arrow function after this type parameter declaration"); + } + } + this.state.context.pop(); + + return inner.apply(this, args); + }; + }); + + // handle return types for arrow functions + instance.extend("parseArrow", function (inner) { + return function (node) { + if (this.match(_types.types.colon)) { + var state = this.state.clone(); + try { + var returnType = this.flowParseTypeAnnotation(); + if (this.canInsertSemicolon()) this.unexpected(); + if (!this.match(_types.types.arrow)) this.unexpected(); + // assign after it is clear it is an arrow + node.returnType = returnType; + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + } else { + throw err; + } + } + } + + return inner.call(this, node); + }; + }); + + instance.extend("shouldParseArrow", function (inner) { + return function () { + return this.match(_types.types.colon) || inner.call(this); + }; + }); + + instance.extend("isClassMutatorStarter", function (inner) { + return function () { + if (this.isRelational("<")) { + return true; + } else { + return inner.call(this); + } + }; + }); +}; + +var _types = require("../tokenizer/types"); + +var _context = require("../tokenizer/context"); + +var _parser = require("../parser"); + +var _parser2 = _interopRequireDefault(_parser); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var pp = _parser2.default.prototype; /* eslint indent: 0 */ +/* eslint max-len: 0 */ + +pp.flowParseTypeInitialiser = function (tok, allowLeadingPipeOrAnd) { + var oldInType = this.state.inType; + this.state.inType = true; + this.expect(tok || _types.types.colon); + if (allowLeadingPipeOrAnd) { + if (this.match(_types.types.bitwiseAND) || this.match(_types.types.bitwiseOR)) { + this.next(); + } + } + var type = this.flowParseType(); + this.state.inType = oldInType; + return type; +}; + +pp.flowParseDeclareClass = function (node) { + this.next(); + this.flowParseInterfaceish(node, true); + return this.finishNode(node, "DeclareClass"); +}; + +pp.flowParseDeclareFunction = function (node) { + this.next(); + + var id = node.id = this.parseIdentifier(); + + var typeNode = this.startNode(); + var typeContainer = this.startNode(); + + if (this.isRelational("<")) { + typeNode.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + typeNode.typeParameters = null; + } + + this.expect(_types.types.parenL); + var tmp = this.flowParseFunctionTypeParams(); + typeNode.params = tmp.params; + typeNode.rest = tmp.rest; + this.expect(_types.types.parenR); + typeNode.returnType = this.flowParseTypeInitialiser(); + + typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation"); + id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation"); + + this.finishNode(id, id.type); + + this.semicolon(); + + return this.finishNode(node, "DeclareFunction"); +}; + +pp.flowParseDeclare = function (node) { + if (this.match(_types.types._class)) { + return this.flowParseDeclareClass(node); + } else if (this.match(_types.types._function)) { + return this.flowParseDeclareFunction(node); + } else if (this.match(_types.types._var)) { + return this.flowParseDeclareVariable(node); + } else if (this.isContextual("module")) { + if (this.lookahead().type === _types.types.dot) { + return this.flowParseDeclareModuleExports(node); + } else { + return this.flowParseDeclareModule(node); + } + } else if (this.isContextual("type")) { + return this.flowParseDeclareTypeAlias(node); + } else if (this.isContextual("interface")) { + return this.flowParseDeclareInterface(node); + } else { + this.unexpected(); + } +}; + +pp.flowParseDeclareVariable = function (node) { + this.next(); + node.id = this.flowParseTypeAnnotatableIdentifier(); + this.semicolon(); + return this.finishNode(node, "DeclareVariable"); +}; + +pp.flowParseDeclareModule = function (node) { + this.next(); + + if (this.match(_types.types.string)) { + node.id = this.parseExprAtom(); + } else { + node.id = this.parseIdentifier(); + } + + var bodyNode = node.body = this.startNode(); + var body = bodyNode.body = []; + this.expect(_types.types.braceL); + while (!this.match(_types.types.braceR)) { + var node2 = this.startNode(); + + this.expectContextual("declare", "Unexpected token. Only declares are allowed inside declare module"); + + body.push(this.flowParseDeclare(node2)); + } + this.expect(_types.types.braceR); + + this.finishNode(bodyNode, "BlockStatement"); + return this.finishNode(node, "DeclareModule"); +}; + +pp.flowParseDeclareModuleExports = function (node) { + this.expectContextual("module"); + this.expect(_types.types.dot); + this.expectContextual("exports"); + node.typeAnnotation = this.flowParseTypeAnnotation(); + return this.finishNode(node, "DeclareModuleExports"); +}; + +pp.flowParseDeclareTypeAlias = function (node) { + this.next(); + this.flowParseTypeAlias(node); + return this.finishNode(node, "DeclareTypeAlias"); +}; + +pp.flowParseDeclareInterface = function (node) { + this.next(); + this.flowParseInterfaceish(node); + return this.finishNode(node, "DeclareInterface"); +}; + +// Interfaces + +pp.flowParseInterfaceish = function (node, allowStatic) { + node.id = this.parseIdentifier(); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + node.typeParameters = null; + } + + node.extends = []; + node.mixins = []; + + if (this.eat(_types.types._extends)) { + do { + node.extends.push(this.flowParseInterfaceExtends()); + } while (this.eat(_types.types.comma)); + } + + if (this.isContextual("mixins")) { + this.next(); + do { + node.mixins.push(this.flowParseInterfaceExtends()); + } while (this.eat(_types.types.comma)); + } + + node.body = this.flowParseObjectType(allowStatic); +}; + +pp.flowParseInterfaceExtends = function () { + var node = this.startNode(); + + node.id = this.flowParseQualifiedTypeIdentifier(); + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterInstantiation(); + } else { + node.typeParameters = null; + } + + return this.finishNode(node, "InterfaceExtends"); +}; + +pp.flowParseInterface = function (node) { + this.flowParseInterfaceish(node, false); + return this.finishNode(node, "InterfaceDeclaration"); +}; + +// Type aliases + +pp.flowParseTypeAlias = function (node) { + node.id = this.parseIdentifier(); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + node.typeParameters = null; + } + + node.right = this.flowParseTypeInitialiser(_types.types.eq, + /*allowLeadingPipeOrAnd*/true); + this.semicolon(); + + return this.finishNode(node, "TypeAlias"); +}; + +// Type annotations + +pp.flowParseTypeParameter = function () { + var node = this.startNode(); + + var variance = void 0; + if (this.match(_types.types.plusMin)) { + if (this.state.value === "+") { + variance = "plus"; + } else if (this.state.value === "-") { + variance = "minus"; + } + this.eat(_types.types.plusMin); + } + + var ident = this.flowParseTypeAnnotatableIdentifier(false, false); + node.name = ident.name; + node.variance = variance; + node.bound = ident.typeAnnotation; + + if (this.match(_types.types.eq)) { + this.eat(_types.types.eq); + node.default = this.flowParseType(); + } + + return this.finishNode(node, "TypeParameter"); +}; + +pp.flowParseTypeParameterDeclaration = function () { + var oldInType = this.state.inType; + var node = this.startNode(); + node.params = []; + + this.state.inType = true; + + if (this.isRelational("<") || this.match(_types.types.jsxTagStart)) { + this.next(); + } else { + this.unexpected(); + } + + do { + node.params.push(this.flowParseTypeParameter()); + if (!this.isRelational(">")) { + this.expect(_types.types.comma); + } + } while (!this.isRelational(">")); + this.expectRelational(">"); + + this.state.inType = oldInType; + + return this.finishNode(node, "TypeParameterDeclaration"); +}; + +pp.flowParseTypeParameterInstantiation = function () { + var node = this.startNode(), + oldInType = this.state.inType; + node.params = []; + + this.state.inType = true; + + this.expectRelational("<"); + while (!this.isRelational(">")) { + node.params.push(this.flowParseType()); + if (!this.isRelational(">")) { + this.expect(_types.types.comma); + } + } + this.expectRelational(">"); + + this.state.inType = oldInType; + + return this.finishNode(node, "TypeParameterInstantiation"); +}; + +pp.flowParseObjectPropertyKey = function () { + return this.match(_types.types.num) || this.match(_types.types.string) ? this.parseExprAtom() : this.parseIdentifier(true); +}; + +pp.flowParseObjectTypeIndexer = function (node, isStatic) { + node.static = isStatic; + + this.expect(_types.types.bracketL); + node.id = this.flowParseObjectPropertyKey(); + node.key = this.flowParseTypeInitialiser(); + this.expect(_types.types.bracketR); + node.value = this.flowParseTypeInitialiser(); + + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeIndexer"); +}; + +pp.flowParseObjectTypeMethodish = function (node) { + node.params = []; + node.rest = null; + node.typeParameters = null; + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + + this.expect(_types.types.parenL); + while (this.match(_types.types.name)) { + node.params.push(this.flowParseFunctionTypeParam()); + if (!this.match(_types.types.parenR)) { + this.expect(_types.types.comma); + } + } + + if (this.eat(_types.types.ellipsis)) { + node.rest = this.flowParseFunctionTypeParam(); + } + this.expect(_types.types.parenR); + node.returnType = this.flowParseTypeInitialiser(); + + return this.finishNode(node, "FunctionTypeAnnotation"); +}; + +pp.flowParseObjectTypeMethod = function (startPos, startLoc, isStatic, key) { + var node = this.startNodeAt(startPos, startLoc); + node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(startPos, startLoc)); + node.static = isStatic; + node.key = key; + node.optional = false; + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeProperty"); +}; + +pp.flowParseObjectTypeCallProperty = function (node, isStatic) { + var valueNode = this.startNode(); + node.static = isStatic; + node.value = this.flowParseObjectTypeMethodish(valueNode); + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeCallProperty"); +}; + +pp.flowParseObjectType = function (allowStatic, allowExact) { + var nodeStart = this.startNode(); + var node = void 0; + var propertyKey = void 0; + var isStatic = false; + + nodeStart.callProperties = []; + nodeStart.properties = []; + nodeStart.indexers = []; + + var endDelim = void 0; + var exact = void 0; + if (allowExact && this.match(_types.types.braceBarL)) { + this.expect(_types.types.braceBarL); + endDelim = _types.types.braceBarR; + exact = true; + } else { + this.expect(_types.types.braceL); + endDelim = _types.types.braceR; + exact = false; + } + + nodeStart.exact = exact; + + while (!this.match(endDelim)) { + var optional = false; + var startPos = this.state.start, + startLoc = this.state.startLoc; + node = this.startNode(); + if (allowStatic && this.isContextual("static")) { + this.next(); + isStatic = true; + } + + if (this.match(_types.types.bracketL)) { + nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic)); + } else if (this.match(_types.types.parenL) || this.isRelational("<")) { + nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, allowStatic)); + } else { + if (isStatic && this.match(_types.types.colon)) { + propertyKey = this.parseIdentifier(); + } else { + propertyKey = this.flowParseObjectPropertyKey(); + } + if (this.isRelational("<") || this.match(_types.types.parenL)) { + // This is a method property + nodeStart.properties.push(this.flowParseObjectTypeMethod(startPos, startLoc, isStatic, propertyKey)); + } else { + if (this.eat(_types.types.question)) { + optional = true; + } + node.key = propertyKey; + node.value = this.flowParseTypeInitialiser(); + node.optional = optional; + node.static = isStatic; + this.flowObjectTypeSemicolon(); + nodeStart.properties.push(this.finishNode(node, "ObjectTypeProperty")); + } + } + + isStatic = false; + } + + this.expect(endDelim); + + return this.finishNode(nodeStart, "ObjectTypeAnnotation"); +}; + +pp.flowObjectTypeSemicolon = function () { + if (!this.eat(_types.types.semi) && !this.eat(_types.types.comma) && !this.match(_types.types.braceR) && !this.match(_types.types.braceBarR)) { + this.unexpected(); + } +}; + +pp.flowParseQualifiedTypeIdentifier = function (startPos, startLoc, id) { + startPos = startPos || this.state.start; + startLoc = startLoc || this.state.startLoc; + var node = id || this.parseIdentifier(); + + while (this.eat(_types.types.dot)) { + var node2 = this.startNodeAt(startPos, startLoc); + node2.qualification = node; + node2.id = this.parseIdentifier(); + node = this.finishNode(node2, "QualifiedTypeIdentifier"); + } + + return node; +}; + +pp.flowParseGenericType = function (startPos, startLoc, id) { + var node = this.startNodeAt(startPos, startLoc); + + node.typeParameters = null; + node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterInstantiation(); + } + + return this.finishNode(node, "GenericTypeAnnotation"); +}; + +pp.flowParseTypeofType = function () { + var node = this.startNode(); + this.expect(_types.types._typeof); + node.argument = this.flowParsePrimaryType(); + return this.finishNode(node, "TypeofTypeAnnotation"); +}; + +pp.flowParseTupleType = function () { + var node = this.startNode(); + node.types = []; + this.expect(_types.types.bracketL); + // We allow trailing commas + while (this.state.pos < this.input.length && !this.match(_types.types.bracketR)) { + node.types.push(this.flowParseType()); + if (this.match(_types.types.bracketR)) break; + this.expect(_types.types.comma); + } + this.expect(_types.types.bracketR); + return this.finishNode(node, "TupleTypeAnnotation"); +}; + +pp.flowParseFunctionTypeParam = function () { + var optional = false; + var node = this.startNode(); + node.name = this.parseIdentifier(); + if (this.eat(_types.types.question)) { + optional = true; + } + node.optional = optional; + node.typeAnnotation = this.flowParseTypeInitialiser(); + return this.finishNode(node, "FunctionTypeParam"); +}; + +pp.flowParseFunctionTypeParams = function () { + var ret = { params: [], rest: null }; + while (this.match(_types.types.name)) { + ret.params.push(this.flowParseFunctionTypeParam()); + if (!this.match(_types.types.parenR)) { + this.expect(_types.types.comma); + } + } + if (this.eat(_types.types.ellipsis)) { + ret.rest = this.flowParseFunctionTypeParam(); + } + return ret; +}; + +pp.flowIdentToTypeAnnotation = function (startPos, startLoc, node, id) { + switch (id.name) { + case "any": + return this.finishNode(node, "AnyTypeAnnotation"); + + case "void": + return this.finishNode(node, "VoidTypeAnnotation"); + + case "bool": + case "boolean": + return this.finishNode(node, "BooleanTypeAnnotation"); + + case "mixed": + return this.finishNode(node, "MixedTypeAnnotation"); + + case "number": + return this.finishNode(node, "NumberTypeAnnotation"); + + case "string": + return this.finishNode(node, "StringTypeAnnotation"); + + default: + return this.flowParseGenericType(startPos, startLoc, id); + } +}; + +// The parsing of types roughly parallels the parsing of expressions, and +// primary types are kind of like primary expressions...they're the +// primitives with which other types are constructed. +pp.flowParsePrimaryType = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var node = this.startNode(); + var tmp = void 0; + var type = void 0; + var isGroupedType = false; + + switch (this.state.type) { + case _types.types.name: + return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdentifier()); + + case _types.types.braceL: + return this.flowParseObjectType(false, false); + + case _types.types.braceBarL: + return this.flowParseObjectType(false, true); + + case _types.types.bracketL: + return this.flowParseTupleType(); + + case _types.types.relational: + if (this.state.value === "<") { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + this.expect(_types.types.parenL); + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + this.expect(_types.types.parenR); + + this.expect(_types.types.arrow); + + node.returnType = this.flowParseType(); + + return this.finishNode(node, "FunctionTypeAnnotation"); + } + break; + + case _types.types.parenL: + this.next(); + + // Check to see if this is actually a grouped type + if (!this.match(_types.types.parenR) && !this.match(_types.types.ellipsis)) { + if (this.match(_types.types.name)) { + var token = this.lookahead().type; + isGroupedType = token !== _types.types.question && token !== _types.types.colon; + } else { + isGroupedType = true; + } + } + + if (isGroupedType) { + type = this.flowParseType(); + this.expect(_types.types.parenR); + return type; + } + + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + + this.expect(_types.types.parenR); + + this.expect(_types.types.arrow); + + node.returnType = this.flowParseType(); + node.typeParameters = null; + + return this.finishNode(node, "FunctionTypeAnnotation"); + + case _types.types.string: + node.value = this.state.value; + this.addExtra(node, "rawValue", node.value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); + this.next(); + return this.finishNode(node, "StringLiteralTypeAnnotation"); + + case _types.types._true:case _types.types._false: + node.value = this.match(_types.types._true); + this.next(); + return this.finishNode(node, "BooleanLiteralTypeAnnotation"); + + case _types.types.plusMin: + if (this.state.value === "-") { + this.next(); + if (!this.match(_types.types.num)) this.unexpected(); + + node.value = -this.state.value; + this.addExtra(node, "rawValue", node.value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); + this.next(); + return this.finishNode(node, "NumericLiteralTypeAnnotation"); + } + + case _types.types.num: + node.value = this.state.value; + this.addExtra(node, "rawValue", node.value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); + this.next(); + return this.finishNode(node, "NumericLiteralTypeAnnotation"); + + case _types.types._null: + node.value = this.match(_types.types._null); + this.next(); + return this.finishNode(node, "NullLiteralTypeAnnotation"); + + case _types.types._this: + node.value = this.match(_types.types._this); + this.next(); + return this.finishNode(node, "ThisTypeAnnotation"); + + case _types.types.star: + this.next(); + return this.finishNode(node, "ExistentialTypeParam"); + + default: + if (this.state.type.keyword === "typeof") { + return this.flowParseTypeofType(); + } + } + + this.unexpected(); +}; + +pp.flowParsePostfixType = function () { + var node = this.startNode(); + var type = node.elementType = this.flowParsePrimaryType(); + if (this.match(_types.types.bracketL)) { + this.expect(_types.types.bracketL); + this.expect(_types.types.bracketR); + return this.finishNode(node, "ArrayTypeAnnotation"); + } else { + return type; + } +}; + +pp.flowParsePrefixType = function () { + var node = this.startNode(); + if (this.eat(_types.types.question)) { + node.typeAnnotation = this.flowParsePrefixType(); + return this.finishNode(node, "NullableTypeAnnotation"); + } else { + return this.flowParsePostfixType(); + } +}; + +pp.flowParseIntersectionType = function () { + var node = this.startNode(); + var type = this.flowParsePrefixType(); + node.types = [type]; + while (this.eat(_types.types.bitwiseAND)) { + node.types.push(this.flowParsePrefixType()); + } + return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation"); +}; + +pp.flowParseUnionType = function () { + var node = this.startNode(); + var type = this.flowParseIntersectionType(); + node.types = [type]; + while (this.eat(_types.types.bitwiseOR)) { + node.types.push(this.flowParseIntersectionType()); + } + return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation"); +}; + +pp.flowParseType = function () { + var oldInType = this.state.inType; + this.state.inType = true; + var type = this.flowParseUnionType(); + this.state.inType = oldInType; + return type; +}; + +pp.flowParseTypeAnnotation = function () { + var node = this.startNode(); + node.typeAnnotation = this.flowParseTypeInitialiser(); + return this.finishNode(node, "TypeAnnotation"); +}; + +pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOptionalParam) { + + var ident = this.parseIdentifier(); + var isOptionalParam = false; + + if (canBeOptionalParam && this.eat(_types.types.question)) { + this.expect(_types.types.question); + isOptionalParam = true; + } + + if (requireTypeAnnotation || this.match(_types.types.colon)) { + ident.typeAnnotation = this.flowParseTypeAnnotation(); + this.finishNode(ident, ident.type); + } + + if (isOptionalParam) { + ident.optional = true; + this.finishNode(ident, ident.type); + } + + return ident; +}; + +pp.typeCastToParameter = function (node) { + node.expression.typeAnnotation = node.typeAnnotation; + + return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end); +};
\ No newline at end of file diff --git a/node_modules/babylon/lib/plugins/jsx/index.js b/node_modules/babylon/lib/plugins/jsx/index.js new file mode 100644 index 000000000..ed7a4ed67 --- /dev/null +++ b/node_modules/babylon/lib/plugins/jsx/index.js @@ -0,0 +1,482 @@ +"use strict"; + +exports.__esModule = true; + +exports.default = function (instance) { + instance.extend("parseExprAtom", function (inner) { + return function (refShortHandDefaultPos) { + if (this.match(_types.types.jsxText)) { + var node = this.parseLiteral(this.state.value, "JSXText"); + // https://github.com/babel/babel/issues/2078 + node.extra = null; + return node; + } else if (this.match(_types.types.jsxTagStart)) { + return this.jsxParseElement(); + } else { + return inner.call(this, refShortHandDefaultPos); + } + }; + }); + + instance.extend("readToken", function (inner) { + return function (code) { + var context = this.curContext(); + + if (context === _context.types.j_expr) { + return this.jsxReadToken(); + } + + if (context === _context.types.j_oTag || context === _context.types.j_cTag) { + if ((0, _identifier.isIdentifierStart)(code)) { + return this.jsxReadWord(); + } + + if (code === 62) { + ++this.state.pos; + return this.finishToken(_types.types.jsxTagEnd); + } + + if ((code === 34 || code === 39) && context === _context.types.j_oTag) { + return this.jsxReadString(code); + } + } + + if (code === 60 && this.state.exprAllowed) { + ++this.state.pos; + return this.finishToken(_types.types.jsxTagStart); + } + + return inner.call(this, code); + }; + }); + + instance.extend("updateContext", function (inner) { + return function (prevType) { + if (this.match(_types.types.braceL)) { + var curContext = this.curContext(); + if (curContext === _context.types.j_oTag) { + this.state.context.push(_context.types.braceExpression); + } else if (curContext === _context.types.j_expr) { + this.state.context.push(_context.types.templateQuasi); + } else { + inner.call(this, prevType); + } + this.state.exprAllowed = true; + } else if (this.match(_types.types.slash) && prevType === _types.types.jsxTagStart) { + this.state.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore + this.state.context.push(_context.types.j_cTag); // reconsider as closing tag context + this.state.exprAllowed = false; + } else { + return inner.call(this, prevType); + } + }; + }); +}; + +var _xhtml = require("./xhtml"); + +var _xhtml2 = _interopRequireDefault(_xhtml); + +var _types = require("../../tokenizer/types"); + +var _context = require("../../tokenizer/context"); + +var _parser = require("../../parser"); + +var _parser2 = _interopRequireDefault(_parser); + +var _identifier = require("../../util/identifier"); + +var _whitespace = require("../../util/whitespace"); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/* eslint indent: 0 */ + +var HEX_NUMBER = /^[\da-fA-F]+$/; +var DECIMAL_NUMBER = /^\d+$/; + +_context.types.j_oTag = new _context.TokContext("<tag", false); +_context.types.j_cTag = new _context.TokContext("</tag", false); +_context.types.j_expr = new _context.TokContext("<tag>...</tag>", true, true); + +_types.types.jsxName = new _types.TokenType("jsxName"); +_types.types.jsxText = new _types.TokenType("jsxText", { beforeExpr: true }); +_types.types.jsxTagStart = new _types.TokenType("jsxTagStart", { startsExpr: true }); +_types.types.jsxTagEnd = new _types.TokenType("jsxTagEnd"); + +_types.types.jsxTagStart.updateContext = function () { + this.state.context.push(_context.types.j_expr); // treat as beginning of JSX expression + this.state.context.push(_context.types.j_oTag); // start opening tag context + this.state.exprAllowed = false; +}; + +_types.types.jsxTagEnd.updateContext = function (prevType) { + var out = this.state.context.pop(); + if (out === _context.types.j_oTag && prevType === _types.types.slash || out === _context.types.j_cTag) { + this.state.context.pop(); + this.state.exprAllowed = this.curContext() === _context.types.j_expr; + } else { + this.state.exprAllowed = true; + } +}; + +var pp = _parser2.default.prototype; + +// Reads inline JSX contents token. + +pp.jsxReadToken = function () { + var out = ""; + var chunkStart = this.state.pos; + for (;;) { + if (this.state.pos >= this.input.length) { + this.raise(this.state.start, "Unterminated JSX contents"); + } + + var ch = this.input.charCodeAt(this.state.pos); + + switch (ch) { + case 60: // "<" + case 123: + // "{" + if (this.state.pos === this.state.start) { + if (ch === 60 && this.state.exprAllowed) { + ++this.state.pos; + return this.finishToken(_types.types.jsxTagStart); + } + return this.getTokenFromCode(ch); + } + out += this.input.slice(chunkStart, this.state.pos); + return this.finishToken(_types.types.jsxText, out); + + case 38: + // "&" + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadEntity(); + chunkStart = this.state.pos; + break; + + default: + if ((0, _whitespace.isNewLine)(ch)) { + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadNewLine(true); + chunkStart = this.state.pos; + } else { + ++this.state.pos; + } + } + } +}; + +pp.jsxReadNewLine = function (normalizeCRLF) { + var ch = this.input.charCodeAt(this.state.pos); + var out = void 0; + ++this.state.pos; + if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) { + ++this.state.pos; + out = normalizeCRLF ? "\n" : "\r\n"; + } else { + out = String.fromCharCode(ch); + } + ++this.state.curLine; + this.state.lineStart = this.state.pos; + + return out; +}; + +pp.jsxReadString = function (quote) { + var out = ""; + var chunkStart = ++this.state.pos; + for (;;) { + if (this.state.pos >= this.input.length) { + this.raise(this.state.start, "Unterminated string constant"); + } + + var ch = this.input.charCodeAt(this.state.pos); + if (ch === quote) break; + if (ch === 38) { + // "&" + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadEntity(); + chunkStart = this.state.pos; + } else if ((0, _whitespace.isNewLine)(ch)) { + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadNewLine(false); + chunkStart = this.state.pos; + } else { + ++this.state.pos; + } + } + out += this.input.slice(chunkStart, this.state.pos++); + return this.finishToken(_types.types.string, out); +}; + +pp.jsxReadEntity = function () { + var str = ""; + var count = 0; + var entity = void 0; + var ch = this.input[this.state.pos]; + + var startPos = ++this.state.pos; + while (this.state.pos < this.input.length && count++ < 10) { + ch = this.input[this.state.pos++]; + if (ch === ";") { + if (str[0] === "#") { + if (str[1] === "x") { + str = str.substr(2); + if (HEX_NUMBER.test(str)) entity = String.fromCharCode(parseInt(str, 16)); + } else { + str = str.substr(1); + if (DECIMAL_NUMBER.test(str)) entity = String.fromCharCode(parseInt(str, 10)); + } + } else { + entity = _xhtml2.default[str]; + } + break; + } + str += ch; + } + if (!entity) { + this.state.pos = startPos; + return "&"; + } + return entity; +}; + +// 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. + +pp.jsxReadWord = function () { + var ch = void 0; + var start = this.state.pos; + do { + ch = this.input.charCodeAt(++this.state.pos); + } while ((0, _identifier.isIdentifierChar)(ch) || ch === 45); // "-" + return this.finishToken(_types.types.jsxName, this.input.slice(start, this.state.pos)); +}; + +// Transforms JSX element name to string. + +function getQualifiedJSXName(object) { + if (object.type === "JSXIdentifier") { + return object.name; + } + + if (object.type === "JSXNamespacedName") { + return object.namespace.name + ":" + object.name.name; + } + + if (object.type === "JSXMemberExpression") { + return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property); + } +} + +// Parse next token as JSX identifier + +pp.jsxParseIdentifier = function () { + var node = this.startNode(); + if (this.match(_types.types.jsxName)) { + node.name = this.state.value; + } else if (this.state.type.keyword) { + node.name = this.state.type.keyword; + } else { + this.unexpected(); + } + this.next(); + return this.finishNode(node, "JSXIdentifier"); +}; + +// Parse namespaced identifier. + +pp.jsxParseNamespacedName = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var name = this.jsxParseIdentifier(); + if (!this.eat(_types.types.colon)) return name; + + var node = this.startNodeAt(startPos, startLoc); + node.namespace = name; + node.name = this.jsxParseIdentifier(); + return this.finishNode(node, "JSXNamespacedName"); +}; + +// Parses element name in any form - namespaced, member +// or single identifier. + +pp.jsxParseElementName = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var node = this.jsxParseNamespacedName(); + while (this.eat(_types.types.dot)) { + var newNode = this.startNodeAt(startPos, startLoc); + newNode.object = node; + newNode.property = this.jsxParseIdentifier(); + node = this.finishNode(newNode, "JSXMemberExpression"); + } + return node; +}; + +// Parses any type of JSX attribute value. + +pp.jsxParseAttributeValue = function () { + var node = void 0; + switch (this.state.type) { + case _types.types.braceL: + node = this.jsxParseExpressionContainer(); + if (node.expression.type === "JSXEmptyExpression") { + this.raise(node.start, "JSX attributes must only be assigned a non-empty expression"); + } else { + return node; + } + + case _types.types.jsxTagStart: + case _types.types.string: + node = this.parseExprAtom(); + node.extra = null; + return node; + + default: + this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text"); + } +}; + +// JSXEmptyExpression is unique type since it doesn't actually parse anything, +// and so it should start at the end of last read token (left brace) and finish +// at the beginning of the next one (right brace). + +pp.jsxParseEmptyExpression = function () { + var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc); + return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc); +}; + +// Parse JSX spread child + +pp.jsxParseSpreadChild = function () { + var node = this.startNode(); + this.expect(_types.types.braceL); + this.expect(_types.types.ellipsis); + node.expression = this.parseExpression(); + this.expect(_types.types.braceR); + + return this.finishNode(node, "JSXSpreadChild"); +}; + +// Parses JSX expression enclosed into curly brackets. + + +pp.jsxParseExpressionContainer = function () { + var node = this.startNode(); + this.next(); + if (this.match(_types.types.braceR)) { + node.expression = this.jsxParseEmptyExpression(); + } else { + node.expression = this.parseExpression(); + } + this.expect(_types.types.braceR); + return this.finishNode(node, "JSXExpressionContainer"); +}; + +// Parses following JSX attribute name-value pair. + +pp.jsxParseAttribute = function () { + var node = this.startNode(); + if (this.eat(_types.types.braceL)) { + this.expect(_types.types.ellipsis); + node.argument = this.parseMaybeAssign(); + this.expect(_types.types.braceR); + return this.finishNode(node, "JSXSpreadAttribute"); + } + node.name = this.jsxParseNamespacedName(); + node.value = this.eat(_types.types.eq) ? this.jsxParseAttributeValue() : null; + return this.finishNode(node, "JSXAttribute"); +}; + +// Parses JSX opening tag starting after "<". + +pp.jsxParseOpeningElementAt = function (startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + node.attributes = []; + node.name = this.jsxParseElementName(); + while (!this.match(_types.types.slash) && !this.match(_types.types.jsxTagEnd)) { + node.attributes.push(this.jsxParseAttribute()); + } + node.selfClosing = this.eat(_types.types.slash); + this.expect(_types.types.jsxTagEnd); + return this.finishNode(node, "JSXOpeningElement"); +}; + +// Parses JSX closing tag starting after "</". + +pp.jsxParseClosingElementAt = function (startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + node.name = this.jsxParseElementName(); + this.expect(_types.types.jsxTagEnd); + return this.finishNode(node, "JSXClosingElement"); +}; + +// Parses entire JSX element, including it"s opening tag +// (starting after "<"), attributes, contents and closing tag. + +pp.jsxParseElementAt = function (startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + var children = []; + var openingElement = this.jsxParseOpeningElementAt(startPos, startLoc); + var closingElement = null; + + if (!openingElement.selfClosing) { + contents: for (;;) { + switch (this.state.type) { + case _types.types.jsxTagStart: + startPos = this.state.start;startLoc = this.state.startLoc; + this.next(); + if (this.eat(_types.types.slash)) { + closingElement = this.jsxParseClosingElementAt(startPos, startLoc); + break contents; + } + children.push(this.jsxParseElementAt(startPos, startLoc)); + break; + + case _types.types.jsxText: + children.push(this.parseExprAtom()); + break; + + case _types.types.braceL: + if (this.lookahead().type === _types.types.ellipsis) { + children.push(this.jsxParseSpreadChild()); + } else { + children.push(this.jsxParseExpressionContainer()); + } + + break; + + default: + this.unexpected(); + } + } + + if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { + this.raise(closingElement.start, "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">"); + } + } + + node.openingElement = openingElement; + node.closingElement = closingElement; + node.children = children; + if (this.match(_types.types.relational) && this.state.value === "<") { + this.raise(this.state.start, "Adjacent JSX elements must be wrapped in an enclosing tag"); + } + return this.finishNode(node, "JSXElement"); +}; + +// Parses entire JSX element from current position. + +pp.jsxParseElement = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + this.next(); + return this.jsxParseElementAt(startPos, startLoc); +};
\ No newline at end of file diff --git a/node_modules/babylon/lib/plugins/jsx/xhtml.js b/node_modules/babylon/lib/plugins/jsx/xhtml.js new file mode 100644 index 000000000..ec21b2cd4 --- /dev/null +++ b/node_modules/babylon/lib/plugins/jsx/xhtml.js @@ -0,0 +1,258 @@ +"use strict"; + +exports.__esModule = true; +exports.default = { + quot: "\"", + amp: "&", + apos: "'", + lt: "<", + gt: ">", + nbsp: " ", + iexcl: "¡", + cent: "¢", + pound: "£", + curren: "¤", + yen: "¥", + brvbar: "¦", + sect: "§", + uml: "¨", + copy: "©", + ordf: "ª", + laquo: "«", + not: "¬", + shy: "", + reg: "®", + macr: "¯", + deg: "°", + plusmn: "±", + sup2: "²", + sup3: "³", + acute: "´", + micro: "µ", + para: "¶", + middot: "·", + cedil: "¸", + sup1: "¹", + ordm: "º", + raquo: "»", + frac14: "¼", + frac12: "½", + frac34: "¾", + iquest: "¿", + Agrave: "À", + Aacute: "Á", + Acirc: "Â", + Atilde: "Ã", + Auml: "Ä", + Aring: "Å", + AElig: "Æ", + Ccedil: "Ç", + Egrave: "È", + Eacute: "É", + Ecirc: "Ê", + Euml: "Ë", + Igrave: "Ì", + Iacute: "Í", + Icirc: "Î", + Iuml: "Ï", + ETH: "Ð", + Ntilde: "Ñ", + Ograve: "Ò", + Oacute: "Ó", + Ocirc: "Ô", + Otilde: "Õ", + Ouml: "Ö", + times: "×", + Oslash: "Ø", + Ugrave: "Ù", + Uacute: "Ú", + Ucirc: "Û", + Uuml: "Ü", + Yacute: "Ý", + THORN: "Þ", + szlig: "ß", + agrave: "à", + aacute: "á", + acirc: "â", + atilde: "ã", + auml: "ä", + aring: "å", + aelig: "æ", + ccedil: "ç", + egrave: "è", + eacute: "é", + ecirc: "ê", + euml: "ë", + igrave: "ì", + iacute: "í", + icirc: "î", + iuml: "ï", + eth: "ð", + ntilde: "ñ", + ograve: "ò", + oacute: "ó", + ocirc: "ô", + otilde: "õ", + ouml: "ö", + divide: "÷", + oslash: "ø", + ugrave: "ù", + uacute: "ú", + ucirc: "û", + uuml: "ü", + yacute: "ý", + thorn: "þ", + yuml: "ÿ", + OElig: "Œ", + oelig: "œ", + Scaron: "Š", + scaron: "š", + Yuml: "Ÿ", + fnof: "ƒ", + circ: "ˆ", + tilde: "˜", + Alpha: "Α", + Beta: "Β", + Gamma: "Γ", + Delta: "Δ", + Epsilon: "Ε", + Zeta: "Ζ", + Eta: "Η", + Theta: "Θ", + Iota: "Ι", + Kappa: "Κ", + Lambda: "Λ", + Mu: "Μ", + Nu: "Ν", + Xi: "Ξ", + Omicron: "Ο", + Pi: "Π", + Rho: "Ρ", + Sigma: "Σ", + Tau: "Τ", + Upsilon: "Υ", + Phi: "Φ", + Chi: "Χ", + Psi: "Ψ", + Omega: "Ω", + alpha: "α", + beta: "β", + gamma: "γ", + delta: "δ", + epsilon: "ε", + zeta: "ζ", + eta: "η", + theta: "θ", + iota: "ι", + kappa: "κ", + lambda: "λ", + mu: "μ", + nu: "ν", + xi: "ξ", + omicron: "ο", + pi: "π", + rho: "ρ", + sigmaf: "ς", + sigma: "σ", + tau: "τ", + upsilon: "υ", + phi: "φ", + chi: "χ", + psi: "ψ", + omega: "ω", + thetasym: "ϑ", + upsih: "ϒ", + piv: "ϖ", + ensp: " ", + emsp: " ", + thinsp: " ", + zwnj: "", + zwj: "", + lrm: "", + rlm: "", + ndash: "–", + mdash: "—", + lsquo: "‘", + rsquo: "’", + sbquo: "‚", + ldquo: "“", + rdquo: "”", + bdquo: "„", + dagger: "†", + Dagger: "‡", + bull: "•", + hellip: "…", + permil: "‰", + prime: "′", + Prime: "″", + lsaquo: "‹", + rsaquo: "›", + oline: "‾", + frasl: "⁄", + euro: "€", + image: "ℑ", + weierp: "℘", + real: "ℜ", + trade: "™", + alefsym: "ℵ", + larr: "←", + uarr: "↑", + rarr: "→", + darr: "↓", + harr: "↔", + crarr: "↵", + lArr: "⇐", + uArr: "⇑", + rArr: "⇒", + dArr: "⇓", + hArr: "⇔", + forall: "∀", + part: "∂", + exist: "∃", + empty: "∅", + nabla: "∇", + isin: "∈", + notin: "∉", + ni: "∋", + prod: "∏", + sum: "∑", + minus: "−", + lowast: "∗", + radic: "√", + prop: "∝", + infin: "∞", + ang: "∠", + and: "∧", + or: "∨", + cap: "∩", + cup: "∪", + "int": "∫", + there4: "∴", + sim: "∼", + cong: "≅", + asymp: "≈", + ne: "≠", + equiv: "≡", + le: "≤", + ge: "≥", + sub: "⊂", + sup: "⊃", + nsub: "⊄", + sube: "⊆", + supe: "⊇", + oplus: "⊕", + otimes: "⊗", + perp: "⊥", + sdot: "⋅", + lceil: "⌈", + rceil: "⌉", + lfloor: "⌊", + rfloor: "⌋", + lang: "〈", + rang: "〉", + loz: "◊", + spades: "♠", + clubs: "♣", + hearts: "♥", + diams: "♦" +};
\ No newline at end of file |