+131
| /** | ||
| * Based on the comment attachment algorithm used in espree and estraverse. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
| * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| "use strict"; | ||
| var _state = require("./state"); | ||
| function last(stack) { | ||
| return stack[stack.length - 1]; | ||
| } | ||
| var pp = _state.Parser.prototype; | ||
| pp.addComment = function (comment) { | ||
| this.trailingComments.push(comment); | ||
| this.leadingComments.push(comment); | ||
| }; | ||
| pp.processComment = function (node) { | ||
| var stack = this.bottomRightStack; | ||
| var lastChild; | ||
| var trailingComments; | ||
| var i; | ||
| if (this.trailingComments.length > 0) { | ||
| // If the first comment in trailingComments comes after the | ||
| // current node, then we're good - all comments in the array will | ||
| // come after the node and so it's safe to add then as official | ||
| // trailingComments. | ||
| if (this.trailingComments[0].start >= node.end) { | ||
| trailingComments = this.trailingComments; | ||
| this.trailingComments = []; | ||
| } else { | ||
| // Otherwise, if the first comment doesn't come after the | ||
| // current node, that means we have a mix of leading and trailing | ||
| // comments in the array and that leadingComments contains the | ||
| // same items as trailingComments. Reset trailingComments to | ||
| // zero items and we'll handle this by evaluating leadingComments | ||
| // later. | ||
| this.trailingComments.length = 0; | ||
| } | ||
| } else { | ||
| var lastInStack = last(stack); | ||
| if (stack.length > 0 && lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) { | ||
| trailingComments = lastInStack.trailingComments; | ||
| lastInStack.trailingComments = null; | ||
| } | ||
| } | ||
| // Eating the stack. | ||
| while (stack.length > 0 && last(stack).start >= node.start) { | ||
| lastChild = stack.pop(); | ||
| } | ||
| if (lastChild) { | ||
| if (lastChild.leadingComments && last(lastChild.leadingComments).end <= node.start) { | ||
| node.leadingComments = lastChild.leadingComments; | ||
| lastChild.leadingComments = null; | ||
| } | ||
| } else if (this.leadingComments.length > 0) { | ||
| if (last(this.leadingComments).end <= node.start) { | ||
| node.leadingComments = this.leadingComments; | ||
| this.leadingComments = []; | ||
| } else { | ||
| // https://github.com/eslint/espree/issues/2 | ||
| // | ||
| // In special cases, such as return (without a value) and | ||
| // debugger, all comments will end up as leadingComments and | ||
| // will otherwise be eliminated. This this step runs when the | ||
| // bottomRightStack is empty and there are comments left | ||
| // in leadingComments. | ||
| // | ||
| // This loop figures out the stopping point between the actual | ||
| // leading and trailing comments by finding the location of the | ||
| // first comment that comes after the given node. | ||
| for (i = 0; i < this.leadingComments.length; i++) { | ||
| if (this.leadingComments[i].end > node.start) { | ||
| break; | ||
| } | ||
| } | ||
| // Split the array based on the location of the first comment | ||
| // that comes after the node. Keep in mind that this could | ||
| // result in an empty array, and if so, the array must be | ||
| // deleted. | ||
| node.leadingComments = this.leadingComments.slice(0, i); | ||
| if (node.leadingComments.length === 0) { | ||
| node.leadingComments = null; | ||
| } | ||
| // Similarly, trailing comments are attached later. The variable | ||
| // must be reset to null if there are no trailing comments. | ||
| trailingComments = this.leadingComments.slice(i); | ||
| if (trailingComments.length === 0) { | ||
| trailingComments = null; | ||
| } | ||
| } | ||
| } | ||
| if (trailingComments) { | ||
| if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) { | ||
| node.innerComments = trailingComments; | ||
| } else { | ||
| node.trailingComments = trailingComments; | ||
| } | ||
| } | ||
| stack.push(node); | ||
| }; |
+32
-23
@@ -80,2 +80,3 @@ // A recursive descent parser operates by defining functions for all | ||
| } | ||
| this.toReferencedList(node.expressions); | ||
| return this.finishNode(node, "SequenceExpression"); | ||
@@ -103,3 +104,5 @@ } | ||
| startLoc = this.startLoc; | ||
| if (this.type === _tokentype.types.parenL || this.type === _tokentype.types.name) this.potentialArrowAt = this.start; | ||
| if (this.type === _tokentype.types.parenL || this.type === _tokentype.types.name) { | ||
| this.potentialArrowAt = this.start; | ||
| } | ||
| var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos); | ||
@@ -264,3 +267,5 @@ if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc); | ||
| if (possibleAsync && (this.type === _tokentype.types.colon || this.type === _tokentype.types.arrow)) { | ||
| return this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); | ||
| base = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); | ||
| } else { | ||
| this.toReferencedList(node.arguments); | ||
| } | ||
@@ -337,3 +342,3 @@ } else if (this.type === _tokentype.types.backQuote) { | ||
| return this.parseFunction(node, false, false, true); | ||
| } else if (id.name === "async" && this.type === _tokentype.types.name) { | ||
| } else if (canBeArrow && id.name === "async" && this.type === _tokentype.types.name) { | ||
| var params = [this.parseIdent()]; | ||
@@ -346,3 +351,5 @@ this.expect(_tokentype.types.arrow); | ||
| if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(node, [id]); | ||
| if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) { | ||
| return this.parseArrowExpression(node, [id]); | ||
| } | ||
@@ -362,3 +369,3 @@ return id; | ||
| node = this.startNode(); | ||
| node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true; | ||
| node.rawValue = node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true; | ||
| node.raw = this.type.keyword; | ||
@@ -379,2 +386,3 @@ this.next(); | ||
| node.elements = this.parseExprList(_tokentype.types.bracketR, true, true, refShorthandDefaultPos); | ||
| this.toReferencedList(node.elements); | ||
| return this.finishNode(node, "ArrayExpression"); | ||
@@ -422,3 +430,3 @@ | ||
| var node = this.startNode(); | ||
| node.value = value; | ||
| node.rawValue = node.value = value; | ||
| node.raw = this.input.slice(this.start, this.end); | ||
@@ -478,4 +486,4 @@ this.next(); | ||
| } | ||
| var innerEndPos = this.start, | ||
| innerEndLoc = this.startLoc; | ||
| var innerEndPos = this.start; | ||
| var innerEndLoc = this.startLoc; | ||
| this.expect(_tokentype.types.parenR); | ||
@@ -485,3 +493,3 @@ | ||
| if (innerParenStart) this.unexpected(innerParenStart); | ||
| return this.parseParenArrowList(startPos, startLoc, exprList, isAsync); | ||
| return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, isAsync); | ||
| } | ||
@@ -503,2 +511,3 @@ | ||
| val.expressions = exprList; | ||
| this.toReferencedList(val.expressions); | ||
| this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); | ||
@@ -513,6 +522,2 @@ } else { | ||
| pp.parseParenArrowList = function (startPos, startLoc, exprList, isAsync) { | ||
| return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, isAsync); | ||
| }; | ||
| pp.parseParenItem = function (node) { | ||
@@ -545,2 +550,3 @@ return node; | ||
| node.arguments = this.parseExprList(_tokentype.types.parenR, this.options.features["es7.trailingFunctionCommas"]); | ||
| this.toReferencedList(node.arguments); | ||
| } else { | ||
@@ -781,11 +787,3 @@ node.arguments = []; | ||
| var elt = undefined; | ||
| if (allowEmpty && this.type === _tokentype.types.comma) { | ||
| elt = null; | ||
| } else if (this.type === _tokentype.types.ellipsis) { | ||
| elt = this.parseSpread(refShorthandDefaultPos); | ||
| } else { | ||
| elt = this.parseMaybeAssign(false, refShorthandDefaultPos); | ||
| } | ||
| elts.push(elt); | ||
| elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos)); | ||
| } | ||
@@ -795,2 +793,14 @@ return elts; | ||
| pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) { | ||
| var elt = undefined; | ||
| if (allowEmpty && this.type === _tokentype.types.comma) { | ||
| elt = null; | ||
| } else if (this.type === _tokentype.types.ellipsis) { | ||
| elt = this.parseSpread(refShorthandDefaultPos); | ||
| } else { | ||
| elt = this.parseMaybeAssign(false, refShorthandDefaultPos); | ||
| } | ||
| return elt; | ||
| }; | ||
| // Parse the next token as an identifier. If `liberal` is true (used | ||
@@ -802,3 +812,2 @@ // when parsing properties), it will also convert keywords into | ||
| var node = this.startNode(); | ||
| if (liberal && this.options.allowReserved === "never") liberal = false; | ||
| if (this.type === _tokentype.types.name) { | ||
@@ -805,0 +814,0 @@ if (!liberal && (!this.options.allowReserved && this.isReservedWord(this.value) || this.strict && _identifier.reservedWords.strict(this.value))) this.raise(this.start, "The keyword '" + this.value + "' is reserved"); |
+12
-40
@@ -21,8 +21,16 @@ "use strict"; | ||
| require("./node"); | ||
| require("./location"); | ||
| require("./lookahead"); | ||
| require("./tokentype"); | ||
| var _tokentype = require("./tokentype"); | ||
| require("./tokenize"); | ||
| require("./tokencontext"); | ||
| require("./comments"); | ||
| var _pluginsFlow = require("./plugins/flow"); | ||
@@ -36,40 +44,2 @@ | ||
| exports.Parser = _state.Parser; | ||
| exports.plugins = _state.plugins; | ||
| exports.defaultOptions = _options.defaultOptions; | ||
| var _location = require("./location"); | ||
| exports.SourceLocation = _location.SourceLocation; | ||
| exports.getLineInfo = _location.getLineInfo; | ||
| var _node = require("./node"); | ||
| exports.Node = _node.Node; | ||
| var _tokentype = require("./tokentype"); | ||
| exports.TokenType = _tokentype.TokenType; | ||
| exports.tokTypes = _tokentype.types; | ||
| var _tokencontext = require("./tokencontext"); | ||
| exports.TokContext = _tokencontext.TokContext; | ||
| exports.tokContexts = _tokencontext.types; | ||
| var _identifier = require("./identifier"); | ||
| exports.isIdentifierChar = _identifier.isIdentifierChar; | ||
| exports.isIdentifierStart = _identifier.isIdentifierStart; | ||
| var _tokenize = require("./tokenize"); | ||
| exports.Token = _tokenize.Token; | ||
| var _whitespace = require("./whitespace"); | ||
| exports.isNewLine = _whitespace.isNewLine; | ||
| exports.lineBreak = _whitespace.lineBreak; | ||
| exports.lineBreakG = _whitespace.lineBreakG; | ||
| _state.plugins.flow = _pluginsFlow2["default"]; | ||
@@ -80,2 +50,4 @@ _state.plugins.jsx = _pluginsJsx2["default"]; | ||
| return new _state.Parser(_options.getOptions(options), input).parse(); | ||
| } | ||
| } | ||
| exports.tokTypes = _tokentype.types; |
+1
-2
@@ -33,3 +33,3 @@ "use strict"; | ||
| var SourceLocation = function SourceLocation(p, start, end) { | ||
| var SourceLocation = function SourceLocation(start, end) { | ||
| _classCallCheck(this, SourceLocation); | ||
@@ -39,3 +39,2 @@ | ||
| this.end = end; | ||
| if (p.sourceFile !== null) this.source = p.sourceFile; | ||
| }; | ||
@@ -42,0 +41,0 @@ |
+5
-1
@@ -7,3 +7,3 @@ "use strict"; | ||
| var STATE_KEYS = ["lastTokStartLoc", "lastTokEndLoc", "lastTokStart", "lastTokEnd", "lineStart", "startLoc", "curLine", "endLoc", "start", "pos", "end", "type", "value", "exprAllowed", "potentialArrowAt", "currLine", "input", "inType", "inFunction", "inGenerator", "labels"]; | ||
| var STATE_KEYS = ["lastTokStartLoc", "lastTokEndLoc", "lastTokStart", "lastTokEnd", "lineStart", "startLoc", "curLine", "endLoc", "start", "pos", "end", "type", "value", "exprAllowed", "potentialArrowAt", "currLine", "input", "inType", "inFunction", "inGenerator", "labels", "tokens", "comments"]; | ||
@@ -16,3 +16,5 @@ pp.getState = function () { | ||
| } | ||
| state.comments = this.comments.slice(); | ||
| state.context = this.context.slice(); | ||
| state.tokens = this.tokens.slice(); | ||
| state.labels = this.labels.slice(); | ||
@@ -30,5 +32,7 @@ return state; | ||
| var old = this.getState(); | ||
| this.isLookahead = true; | ||
| this.next(); | ||
| this.isLookahead = false; | ||
| var curr = this.getState(); | ||
@@ -35,0 +39,0 @@ this.setState(old); |
+6
-0
@@ -82,2 +82,8 @@ "use strict"; | ||
| // Convert list of expression atoms to a list of | ||
| pp.toReferencedList = function (exprList) { | ||
| return exprList; | ||
| }; | ||
| // Parses spread element. | ||
@@ -84,0 +90,0 @@ |
+2
-5
@@ -26,9 +26,5 @@ "use strict"; | ||
| if (parser.options.locations) { | ||
| this.loc = new _location.SourceLocation(parser, loc); | ||
| this.loc = new _location.SourceLocation(loc); | ||
| } | ||
| if (parser.options.directSourceFile) { | ||
| this.sourceFile = parser.options.directSourceFile; | ||
| } | ||
| if (parser.options.ranges) { | ||
@@ -64,2 +60,3 @@ this.range = [pos, 0]; | ||
| if (this.options.ranges) node.range[1] = pos; | ||
| this.processComment(node); | ||
| return node; | ||
@@ -66,0 +63,0 @@ } |
+0
-68
@@ -8,4 +8,2 @@ "use strict"; | ||
| var _location = require("./location"); | ||
| // A second optional argument can be given to further configure | ||
@@ -17,11 +15,2 @@ // the parser process. These options are recognized: | ||
| sourceType: "script", | ||
| // `onInsertedSemicolon` can be a callback that will be called | ||
| // when a semicolon is automatically inserted. It will be passed | ||
| // th position of the comma as an offset, and if `locations` is | ||
| // enabled, it is given the location as a `{line, column}` object | ||
| // as second argument. | ||
| onInsertedSemicolon: null, | ||
| // `onTrailingComma` is similar to `onInsertedSemicolon`, but for | ||
| // trailing commas. | ||
| onTrailingComma: null, | ||
| // By default, reserved words are not enforced. Disable | ||
@@ -38,5 +27,2 @@ // `allowReserved` to enforce them. When this option has the | ||
| allowImportExportEverywhere: false, | ||
| // When enabled, hashbang directive in the beginning of file | ||
| // is allowed and treated as a line comment. | ||
| allowHashBang: false, | ||
| // When `locations` is on, `loc` properties holding objects with | ||
@@ -47,19 +33,2 @@ // `start` and `end` properties in `{line, column}` form (with | ||
| locations: false, | ||
| // A function can be passed as `onToken` option, which will | ||
| // cause Acorn to call that function with object in the same | ||
| // format as tokenize() returns. Note that you are not | ||
| // allowed to call the parser from the callback—that will | ||
| // corrupt its internal state. | ||
| onToken: null, | ||
| // A function can be passed as `onComment` option, which will | ||
| // cause Acorn to call that function with `(block, text, start, | ||
| // end)` parameters whenever a comment is skipped. `block` is a | ||
| // boolean indicating whether this is a block (`/* */`) comment, | ||
| // `text` is the content of the comment, and `start` and `end` are | ||
| // character offsets that denote the start and end of the comment. | ||
| // When the `locations` option is on, two more parameters are | ||
| // passed, the full `{line, column}` locations of the start and | ||
| // end of the comments. Note that you are not allowed to call the | ||
| // parser from the callback—that will corrupt its internal state. | ||
| onComment: null, | ||
| // Nodes have their start and end characters offsets recorded in | ||
@@ -74,14 +43,2 @@ // `start` and `end` properties (directly on the node, rather than | ||
| ranges: false, | ||
| // It is possible to parse multiple files into a single AST by | ||
| // passing the tree produced by parsing the first file as | ||
| // `program` option in subsequent parses. This will add the | ||
| // toplevel forms of the parsed file to the `Program` (top) node | ||
| // of an existing parse tree. | ||
| program: null, | ||
| // When `locations` is on, you can pass this to record the source | ||
| // file in every node's `loc` object. | ||
| sourceFile: null, | ||
| // This value, if given, is stored in every node, whether | ||
| // `locations` is on or off. | ||
| directSourceFile: null, | ||
| plugins: {}, | ||
@@ -100,29 +57,4 @@ // Babel-specific options | ||
| options[opt] = opts && _util.has(opts, opt) ? opts[opt] : defaultOptions[opt]; | ||
| }if (Array.isArray(options.onToken)) { | ||
| (function () { | ||
| var tokens = options.onToken; | ||
| options.onToken = function (token) { | ||
| return tokens.push(token); | ||
| }; | ||
| })(); | ||
| } | ||
| if (Array.isArray(options.onComment)) { | ||
| options.onComment = pushComment(options, options.onComment); | ||
| } | ||
| return options; | ||
| } | ||
| function pushComment(options, array) { | ||
| return function (block, text, start, end, startLoc, endLoc) { | ||
| var comment = { | ||
| type: block ? "Block" : "Line", | ||
| value: text, | ||
| start: start, | ||
| end: end | ||
| }; | ||
| if (options.locations) comment.loc = new _location.SourceLocation(this, startLoc, endLoc); | ||
| if (options.ranges) comment.range = [start, end]; | ||
| array.push(comment); | ||
| }; | ||
| } |
+16
-2
@@ -31,2 +31,18 @@ "use strict"; | ||
| // TODO | ||
| pp.isRelational = function (op) { | ||
| return this.type === _tokentype.types.relational && this.value === op; | ||
| }; | ||
| // TODO | ||
| pp.expectRelational = function (op) { | ||
| if (this.isRelational(op)) { | ||
| this.next(); | ||
| } else { | ||
| this.unexpected(); | ||
| } | ||
| }; | ||
| // Tests whether parsed token is a contextual keyword. | ||
@@ -58,3 +74,2 @@ | ||
| if (this.canInsertSemicolon()) { | ||
| if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); | ||
| return true; | ||
@@ -73,3 +88,2 @@ } | ||
| if (this.type === tokType) { | ||
| if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); | ||
| this.next(); | ||
@@ -76,0 +90,0 @@ return true; |
+46
-21
@@ -11,14 +11,2 @@ "use strict"; | ||
| pp.isRelational = function (op) { | ||
| return this.type === _tokentype.types.relational && this.value === op; | ||
| }; | ||
| pp.expectRelational = function (op) { | ||
| if (this.isRelational(op)) { | ||
| this.next(); | ||
| } else { | ||
| this.unexpected(); | ||
| } | ||
| }; | ||
| pp.flowParseTypeInitialiser = function (tok) { | ||
@@ -504,3 +492,3 @@ var oldInType = this.inType; | ||
| case _tokentype.types.string: | ||
| node.value = this.value; | ||
| node.rawValue = node.value = this.value; | ||
| node.raw = this.input.slice(this.start, this.end); | ||
@@ -510,2 +498,8 @@ this.next(); | ||
| case _tokentype.types.num: | ||
| node.rawValue = node.value = this.value; | ||
| node.raw = this.input.slice(this.start, this.end); | ||
| this.next(); | ||
| return this.finishNode(node, "NumberLiteralTypeAnnotation"); | ||
| default: | ||
@@ -713,16 +707,47 @@ if (this.type.keyword === "typeof") { | ||
| instance.extend("parseParenArrowList", function (inner) { | ||
| return function (startPos, startLoc, exprList, isAsync) { | ||
| function typeCastToParameter(node) { | ||
| node.expression.typeAnnotation = node.typeAnnotation; | ||
| return node.expression; | ||
| } | ||
| instance.extend("toAssignableList", function (inner) { | ||
| return function (exprList, isBinding) { | ||
| for (var i = 0; i < exprList.length; i++) { | ||
| var listItem = exprList[i]; | ||
| if (listItem.type === "TypeCastExpression") { | ||
| var expr = listItem.expression; | ||
| expr.typeAnnotation = listItem.typeAnnotation; | ||
| exprList[i] = expr; | ||
| var expr = exprList[i]; | ||
| if (expr && expr.type === "TypeCastExpression") { | ||
| exprList[i] = typeCastToParameter(expr); | ||
| } | ||
| } | ||
| return inner.call(this, startPos, startLoc, exprList, isAsync); | ||
| return inner.call(this, exprList, isBinding); | ||
| }; | ||
| }); | ||
| 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; | ||
| }; | ||
| }); | ||
| instance.extend("parseExprListItem", function (inner) { | ||
| return function (allowEmpty, refShorthandDefaultPos) { | ||
| var container = this.startNode(); | ||
| var node = inner.call(this, allowEmpty, refShorthandDefaultPos); | ||
| if (this.type === _tokentype.types.colon) { | ||
| container._exprListItem = true; | ||
| container.expression = node; | ||
| container.typeAnnotation = this.flowParseTypeAnnotation(); | ||
| return this.finishNode(container, "TypeCastExpression"); | ||
| } else { | ||
| return node; | ||
| } | ||
| }; | ||
| }); | ||
| instance.extend("parseClassProperty", function (inner) { | ||
@@ -729,0 +754,0 @@ return function (node) { |
+16
-4
@@ -14,3 +14,2 @@ "use strict"; | ||
| this.options = options; | ||
| this.sourceFile = this.options.sourceFile || null; | ||
| this.isKeyword = _identifier.keywords[6]; | ||
@@ -66,6 +65,18 @@ this.isReservedWord = _identifier.reservedWords[6]; | ||
| // Leading decorators. | ||
| this.decorators = []; | ||
| // Token store. | ||
| this.tokens = []; | ||
| // Comment store. | ||
| this.comments = []; | ||
| // Comment attachment store | ||
| this.trailingComments = []; | ||
| this.leadingComments = []; | ||
| this.bottomRightStack = []; | ||
| // If enabled, skip leading hashbang line. | ||
| if (this.pos === 0 && this.options.allowHashBang && this.input.slice(0, 2) === "#!") { | ||
| if (this.pos === 0 && this.input[0] === "#" && this.input[1] === "!") { | ||
| this.skipLineComment(2); | ||
@@ -93,5 +104,6 @@ } | ||
| Parser.prototype.parse = function () { | ||
| var node = this.options.program || this.startNode(); | ||
| var file = this.startNode(); | ||
| var program = this.startNode(); | ||
| this.nextToken(); | ||
| return this.parseTopLevel(node); | ||
| return this.parseTopLevel(file, program); | ||
| }; |
+11
-5
@@ -18,8 +18,10 @@ "use strict"; | ||
| pp.parseTopLevel = function (node) { | ||
| pp.parseTopLevel = function (file, program) { | ||
| program.sourceType = this.options.sourceType; | ||
| program.body = []; | ||
| var first = true; | ||
| if (!node.body) node.body = []; | ||
| while (this.type !== _tokentype.types.eof) { | ||
| var stmt = this.parseStatement(true, true); | ||
| node.body.push(stmt); | ||
| program.body.push(stmt); | ||
| if (first) { | ||
@@ -31,4 +33,8 @@ if (this.isUseStrict(stmt)) this.setStrict(true); | ||
| this.next(); | ||
| node.sourceType = this.options.sourceType; | ||
| return this.finishNode(node, "Program"); | ||
| file.program = this.finishNode(program, "Program"); | ||
| file.comments = this.comments; | ||
| file.tokens = this.tokens; | ||
| return this.finishNode(file, "File"); | ||
| }; | ||
@@ -35,0 +41,0 @@ |
+29
-9
@@ -31,3 +31,3 @@ "use strict"; | ||
| if (p.options.locations) { | ||
| this.loc = new _location.SourceLocation(p, p.startLoc, p.endLoc); | ||
| this.loc = new _location.SourceLocation(p.startLoc, p.endLoc); | ||
| } | ||
@@ -53,3 +53,3 @@ | ||
| pp.next = function () { | ||
| if (this.options.onToken && !this.isLookahead) this.options.onToken(new Token(this)); | ||
| if (!this.isLookahead) this.tokens.push(new Token(this)); | ||
@@ -99,3 +99,7 @@ this.lastTokEnd = this.end; | ||
| if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos()); | ||
| if (curContext.override) { | ||
| return curContext.override(this); | ||
| } else { | ||
| return this.readToken(this.fullCharCodeAtPos()); | ||
| } | ||
| }; | ||
@@ -119,7 +123,23 @@ | ||
| function pushComment(block, text, start, end, startLoc, endLoc) { | ||
| var comment = { | ||
| type: block ? "CommentBlock" : "CommentLine", | ||
| value: text, | ||
| start: start, | ||
| end: end, | ||
| loc: new _location.SourceLocation(startLoc, endLoc), | ||
| range: [start, end] | ||
| }; | ||
| this.tokens.push(comment); | ||
| this.comments.push(comment); | ||
| this.addComment(comment); | ||
| } | ||
| pp.skipBlockComment = function () { | ||
| var startLoc = this.options.onComment && this.curPosition(); | ||
| var startLoc = this.curPosition(); | ||
| var start = this.pos, | ||
| end = this.input.indexOf("*/", this.pos += 2); | ||
| if (end === -1) this.raise(this.pos - 2, "Unterminated comment"); | ||
| this.pos = end + 2; | ||
@@ -134,3 +154,4 @@ if (this.options.locations) { | ||
| } | ||
| if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition()); | ||
| pushComment.call(this, true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition()); | ||
| }; | ||
@@ -140,3 +161,3 @@ | ||
| var start = this.pos; | ||
| var startLoc = this.options.onComment && this.curPosition(); | ||
| var startLoc = this.curPosition(); | ||
| var ch = this.input.charCodeAt(this.pos += startSkip); | ||
@@ -147,5 +168,4 @@ while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { | ||
| } | ||
| if (this.options.onComment) { | ||
| this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition()); | ||
| } | ||
| pushComment.call(this, false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition()); | ||
| }; | ||
@@ -152,0 +172,0 @@ |
+1
-1
| { | ||
| "name": "babylon", | ||
| "version": "5.7.2", | ||
| "version": "5.8.2", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
174121
1.82%23
4.55%4587
2.34%22
10%