Comparing version
@@ -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"); |
@@ -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; |
@@ -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 @@ |
@@ -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); |
@@ -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 @@ |
@@ -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 @@ } |
@@ -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); | ||
}; | ||
} |
@@ -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; |
@@ -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) { |
@@ -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); | ||
}; |
@@ -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 @@ |
@@ -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 @@ |
{ | ||
"name": "babylon", | ||
"version": "5.7.2", | ||
"version": "5.8.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", |
174121
1.82%23
4.55%4587
2.34%