shift-parser
Advanced tools
Comparing version 4.1.3 to 5.0.0
@@ -146,2 +146,11 @@ "use strict"; | ||
}, { | ||
key: "reduceAssignmentTargetIdentifier", | ||
value: function reduceAssignmentTargetIdentifier(node) { | ||
var s = this.identity; | ||
if ((0, _utils.isRestrictedWord)(node.name) || (0, _utils.isStrictModeReservedWord)(node.name)) { | ||
s = s.addStrictError(new _earlyErrorState.EarlyError(node, "The identifier " + JSON.stringify(node.name) + " must not be in binding position in strict mode")); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceArrowExpression", | ||
@@ -152,2 +161,5 @@ value: function reduceArrowExpression(node, _ref2) { | ||
var isSimpleParameterList = node.params.rest == null && node.params.items.every(function (i) { | ||
return i.type === "BindingIdentifier"; | ||
}); | ||
params = params.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING); | ||
@@ -168,2 +180,5 @@ if (node.body.type === "FunctionBody") { | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceArrowExpression", this).call(this, node, { params: params, body: body }); | ||
if (!isSimpleParameterList && node.body.type === "FunctionBody" && isStrictFunctionBody(node.body)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Functions with non-simple parameter lists may not contain a \"use strict\" directive")); | ||
} | ||
s = s.clearYieldExpressions(); | ||
@@ -331,16 +346,22 @@ s = s.observeVarBoundary(); | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceExportFrom", this).apply(this, arguments); | ||
if (node.moduleSpecifier != null) { | ||
s = s.clearExportedBindings(); | ||
} | ||
s = s.clearExportedBindings(); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceExportSpecifier", | ||
value: function reduceExportSpecifier(node) { | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceExportSpecifier", this).apply(this, arguments); | ||
s = s.exportName(node.exportedName, node); | ||
s = s.exportBinding(node.name || node.exportedName, node); | ||
key: "reduceExportFromSpecifier", | ||
value: function reduceExportFromSpecifier(node) { | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceExportFromSpecifier", this).apply(this, arguments); | ||
s = s.exportName(node.exportedName || node.name, node); | ||
s = s.exportBinding(node.name, node); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceExportLocalSpecifier", | ||
value: function reduceExportLocalSpecifier(node) { | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceExportLocalSpecifier", this).apply(this, arguments); | ||
s = s.exportName(node.exportedName || node.name.name, node); | ||
s = s.exportBinding(node.name.name, node); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceExportDefault", | ||
@@ -485,2 +506,5 @@ value: function reduceExportDefault(node) { | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceFunctionDeclaration", this).call(this, node, { name: name, params: params, body: body }); | ||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Functions with non-simple parameter lists may not contain a \"use strict\" directive")); | ||
} | ||
s = s.clearYieldExpressions(); | ||
@@ -525,2 +549,5 @@ s = s.observeFunctionDeclaration(); | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceFunctionExpression", this).call(this, node, { name: name, params: params, body: body }); | ||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Functions with non-simple parameter lists may not contain a \"use strict\" directive")); | ||
} | ||
s = s.clearBoundNames(); | ||
@@ -617,5 +644,2 @@ s = s.clearYieldExpressions(); | ||
//} | ||
if (!/^[igmyu]*$/.test(node.flags) || containsDuplicates(node.flags)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Invalid regular expression flags")); | ||
} | ||
return s; | ||
@@ -630,2 +654,5 @@ } | ||
var isSimpleParameterList = node.params.rest == null && node.params.items.every(function (i) { | ||
return i.type === "BindingIdentifier"; | ||
}); | ||
params = params.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING); | ||
@@ -654,2 +681,5 @@ body = body.enforceConflictingLexicallyDeclaredNames(params.lexicallyDeclaredNames, DUPLICATE_BINDING); | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceMethod", this).call(this, node, { name: name, params: params, body: body }); | ||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Functions with non-simple parameter lists may not contain a \"use strict\" directive")); | ||
} | ||
s = s.clearYieldExpressions(); | ||
@@ -753,2 +783,3 @@ s = s.observeVarBoundary(); | ||
var isSimpleParameterList = node.param.type === "BindingIdentifier"; | ||
param = param.observeLexicalDeclaration(); | ||
@@ -768,2 +799,5 @@ param = param.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING); | ||
var s = _get(Object.getPrototypeOf(EarlyErrorChecker.prototype), "reduceSetter", this).call(this, node, { name: name, param: param, body: body }); | ||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) { | ||
s = s.addError(new _earlyErrorState.EarlyError(node, "Functions with non-simple parameter lists may not contain a \"use strict\" directive")); | ||
} | ||
s = s.observeVarBoundary(); | ||
@@ -770,0 +804,0 @@ return s; |
@@ -32,2 +32,3 @@ "use strict"; | ||
UNEXPECTED_LINE_TERMINATOR: "Unexpected line terminator", | ||
UNEXPECTED_COMMA_AFTER_REST: "Unexpected comma after rest", | ||
NEWLINE_AFTER_THROW: "Illegal newline after throw", | ||
@@ -37,2 +38,3 @@ UNTERMINATED_REGEXP: "Invalid regular expression: missing /", | ||
INVALID_LHS_IN_ASSIGNMENT: "Invalid left-hand side in assignment", | ||
INVALID_LHS_IN_BINDING: "Invalid left-hand side in binding", // todo collapse messages? | ||
INVALID_LHS_IN_FOR_IN: "Invalid left-hand side in for-in", | ||
@@ -39,0 +41,0 @@ INVALID_LHS_IN_FOR_OF: "Invalid left-hand side in for-of", |
@@ -6,4 +6,6 @@ "use strict"; | ||
}); | ||
exports.TokenType = exports.TokenClass = exports.Tokenizer = exports.EarlyErrorChecker = exports.parseScript = exports.parseModule = undefined; | ||
exports.TokenType = exports.TokenClass = exports.Tokenizer = exports.ParserWithLocation = exports.GenericParser = exports.EarlyErrorChecker = exports.parseScriptWithLocation = exports.parseModuleWithLocation = exports.parseScript = exports.parseModule = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _tokenizer = require("./tokenizer"); | ||
@@ -36,2 +38,22 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** | ||
* Copyright 2016 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
function markLocation(node, location) { | ||
@@ -48,18 +70,41 @@ node.loc = { | ||
return node; | ||
} /** | ||
* Copyright 2014 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
} | ||
var ParserWithLocation = function (_GenericParser) { | ||
_inherits(ParserWithLocation, _GenericParser); | ||
function ParserWithLocation(source) { | ||
_classCallCheck(this, ParserWithLocation); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ParserWithLocation).call(this, source)); | ||
_this.locations = new WeakMap(); | ||
return _this; | ||
} | ||
_createClass(ParserWithLocation, [{ | ||
key: "startNode", | ||
value: function startNode() { | ||
return this.getLocation(); | ||
} | ||
}, { | ||
key: "finishNode", | ||
value: function finishNode(node, start) { | ||
this.locations.set(node, { | ||
start: start, | ||
end: this.getLocation() | ||
}); | ||
return node; | ||
} | ||
}, { | ||
key: "copyNode", | ||
value: function copyNode(src, dest) { | ||
this.locations.set(dest, this.locations.get(src)); // todo check undefined | ||
return dest; | ||
} | ||
}]); | ||
return ParserWithLocation; | ||
}(_parser.GenericParser); | ||
function generateInterface(parsingFunctionName) { | ||
@@ -69,14 +114,9 @@ return function parse(code) { | ||
var _ref$loc = _ref.loc; | ||
var loc = _ref$loc === undefined ? false : _ref$loc; | ||
var _ref$earlyErrors = _ref.earlyErrors; | ||
var earlyErrors = _ref$earlyErrors === undefined ? true : _ref$earlyErrors; | ||
var parser = new _parser.Parser(code); | ||
if (loc) { | ||
parser.markLocation = markLocation; | ||
} | ||
var ast = parser[parsingFunctionName](); | ||
var parser = new _parser.GenericParser(code); | ||
var tree = parser[parsingFunctionName](); | ||
if (earlyErrors) { | ||
var errors = _earlyErrors.EarlyErrorChecker.check(ast); | ||
var errors = _earlyErrors.EarlyErrorChecker.check(tree); | ||
// for now, just throw the first error; we will handle multiple errors later | ||
@@ -88,15 +128,34 @@ if (errors.length > 0) { | ||
var offset = 0, | ||
line = 1, | ||
column = 0; | ||
if (node.loc != null) { | ||
var _node$loc$start = node.loc.start; | ||
offset = _node$loc$start.offset; | ||
line = _node$loc$start.line; | ||
column = _node$loc$start.column; | ||
} | ||
throw new _tokenizer.JsError(0, 1, 0, message); | ||
} | ||
} | ||
return tree; | ||
}; | ||
} | ||
function generateInterfaceWithLocation(parsingFunctionName) { | ||
return function parse(code) { | ||
var _ref2 = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var _ref2$earlyErrors = _ref2.earlyErrors; | ||
var earlyErrors = _ref2$earlyErrors === undefined ? true : _ref2$earlyErrors; | ||
var parser = new ParserWithLocation(code); | ||
var tree = parser[parsingFunctionName](); | ||
if (earlyErrors) { | ||
var errors = _earlyErrors.EarlyErrorChecker.check(tree); | ||
// for now, just throw the first error; we will handle multiple errors later | ||
if (errors.length > 0) { | ||
var _errors$2 = errors[0]; | ||
var node = _errors$2.node; | ||
var message = _errors$2.message; | ||
var _parser$locations$get = parser.locations.get(node).start; | ||
var offset = _parser$locations$get.offset; | ||
var line = _parser$locations$get.line; | ||
var column = _parser$locations$get.column; | ||
throw new _tokenizer.JsError(offset, line, column, message); | ||
} | ||
} | ||
return ast; | ||
return { tree: tree, locations: parser.locations }; | ||
}; | ||
@@ -107,3 +166,7 @@ } | ||
var parseScript = exports.parseScript = generateInterface("parseScript"); | ||
var parseModuleWithLocation = exports.parseModuleWithLocation = generateInterfaceWithLocation("parseModule"); | ||
var parseScriptWithLocation = exports.parseScriptWithLocation = generateInterfaceWithLocation("parseScript"); | ||
exports.default = parseScript; | ||
exports.EarlyErrorChecker = _earlyErrors.EarlyErrorChecker; | ||
exports.EarlyErrorChecker = _earlyErrors.EarlyErrorChecker; | ||
exports.GenericParser = _parser.GenericParser; | ||
exports.ParserWithLocation = ParserWithLocation; |
@@ -76,2 +76,3 @@ "use strict"; | ||
ASSIGN_MOD: { klass: TokenClass.Punctuator, name: "%=" }, | ||
ASSIGN_EXP: { klass: TokenClass.Punctuator, name: "**=" }, | ||
COMMA: { klass: TokenClass.Punctuator, name: "," }, | ||
@@ -91,2 +92,3 @@ OR: { klass: TokenClass.Punctuator, name: "||" }, | ||
MOD: { klass: TokenClass.Punctuator, name: "%" }, | ||
EXP: { klass: TokenClass.Punctuator, name: "**" }, | ||
EQ: { klass: TokenClass.Punctuator, name: "==" }, | ||
@@ -909,5 +911,11 @@ NE: { klass: TokenClass.Punctuator, name: "!=" }, | ||
} | ||
if (ch1 === "*" && _ch2 === "=") { | ||
return TokenType.ASSIGN_EXP; | ||
} | ||
} | ||
// Other 2-character punctuators: ++ -- << >> && || | ||
switch (ch1) { | ||
case "*": | ||
return TokenType.EXP; | ||
case "+": | ||
@@ -914,0 +922,0 @@ return TokenType.INC; |
{ | ||
"name": "shift-parser", | ||
"version": "4.1.3", | ||
"version": "5.0.0", | ||
"description": "ECMAScript parser that produces a Shift format AST", | ||
@@ -27,3 +27,4 @@ "author": "Shape Security Labs", | ||
"multimap": "^0.1.1", | ||
"shift-reducer": "^3.0.2" | ||
"shift-ast": "^4.0.0", | ||
"shift-reducer": "^4.0.0" | ||
}, | ||
@@ -42,4 +43,4 @@ "devDependencies": { | ||
"microtime": "^2.0.0", | ||
"mocha": "2.2.5", | ||
"shift-spec": "2015.2.1", | ||
"mocha": "2.3.4", | ||
"shift-spec": "^2016.0.0", | ||
"tick": "0.1.1", | ||
@@ -46,0 +47,0 @@ "traceur": "0.0.91", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
279017
5649
5
21802
10
1
0
+ Addedshift-ast@^4.0.0
+ Addedshift-ast@4.0.0(transitive)
+ Addedshift-reducer@4.4.1(transitive)
- Removedshift-reducer@3.0.3(transitive)
- Removedshift-spec@2015.2.1(transitive)
Updatedshift-reducer@^4.0.0