diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/babylon/lib/tokenizer/context.js | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) |
add node_modules to address #4364
Diffstat (limited to 'node_modules/babylon/lib/tokenizer/context.js')
-rw-r--r-- | node_modules/babylon/lib/tokenizer/context.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/node_modules/babylon/lib/tokenizer/context.js b/node_modules/babylon/lib/tokenizer/context.js new file mode 100644 index 000000000..856051a01 --- /dev/null +++ b/node_modules/babylon/lib/tokenizer/context.js @@ -0,0 +1,99 @@ +"use strict"; + +exports.__esModule = true; +exports.types = exports.TokContext = undefined; + +var _types = require("./types"); + +var _whitespace = require("../util/whitespace"); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // The algorithm used to determine whether a regexp can appear at a +// given point in the program is loosely based on sweet.js' approach. +// See https://github.com/mozilla/sweet.js/wiki/design + +var TokContext = exports.TokContext = function TokContext(token, isExpr, preserveSpace, override) { + _classCallCheck(this, TokContext); + + this.token = token; + this.isExpr = !!isExpr; + this.preserveSpace = !!preserveSpace; + this.override = override; +}; + +var types = exports.types = { + braceStatement: new TokContext("{", false), + braceExpression: new TokContext("{", true), + templateQuasi: new TokContext("${", true), + parenStatement: new TokContext("(", false), + parenExpression: new TokContext("(", true), + template: new TokContext("`", true, true, function (p) { + return p.readTmplToken(); + }), + functionExpression: new TokContext("function", true) +}; + +// Token-specific context update code + +_types.types.parenR.updateContext = _types.types.braceR.updateContext = function () { + if (this.state.context.length === 1) { + this.state.exprAllowed = true; + return; + } + + var out = this.state.context.pop(); + if (out === types.braceStatement && this.curContext() === types.functionExpression) { + this.state.context.pop(); + this.state.exprAllowed = false; + } else if (out === types.templateQuasi) { + this.state.exprAllowed = true; + } else { + this.state.exprAllowed = !out.isExpr; + } +}; + +_types.types.name.updateContext = function (prevType) { + this.state.exprAllowed = false; + + if (prevType === _types.types._let || prevType === _types.types._const || prevType === _types.types._var) { + if (_whitespace.lineBreak.test(this.input.slice(this.state.end))) { + this.state.exprAllowed = true; + } + } +}; + +_types.types.braceL.updateContext = function (prevType) { + this.state.context.push(this.braceIsBlock(prevType) ? types.braceStatement : types.braceExpression); + this.state.exprAllowed = true; +}; + +_types.types.dollarBraceL.updateContext = function () { + this.state.context.push(types.templateQuasi); + this.state.exprAllowed = true; +}; + +_types.types.parenL.updateContext = function (prevType) { + var statementParens = prevType === _types.types._if || prevType === _types.types._for || prevType === _types.types._with || prevType === _types.types._while; + this.state.context.push(statementParens ? types.parenStatement : types.parenExpression); + this.state.exprAllowed = true; +}; + +_types.types.incDec.updateContext = function () { + // tokExprAllowed stays unchanged +}; + +_types.types._function.updateContext = function () { + if (this.curContext() !== types.braceStatement) { + this.state.context.push(types.functionExpression); + } + + this.state.exprAllowed = false; +}; + +_types.types.backQuote.updateContext = function () { + if (this.curContext() === types.template) { + this.state.context.pop(); + } else { + this.state.context.push(types.template); + } + this.state.exprAllowed = false; +};
\ No newline at end of file |