: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
(key.type === syntax_1.Syntax.Literal && key.value === value);
Parser.prototype.parseObjectProperty = function (hasProto) {
var node = this.createNode();
var token = this.lookahead;
if (token.type === 3 /* Identifier */) {
computed = this.match('[');
isAsync = !this.hasLineTerminator && (id === 'async') &&
!this.match(':') && !this.match('(') && !this.match('*');
key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
else if (this.match('*')) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
this.throwUnexpectedToken(this.lookahead);
if (this.match(':') && !isAsync) {
if (!computed && this.isPropertyKey(key, '__proto__')) {
this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
value = this.inheritCoverGrammar(this.parseAssignmentExpression);
else if (this.match('(')) {
value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
else if (token.type === 3 /* Identifier */) {
var id = this.finalize(node, new Node.Identifier(token.value));
this.context.firstCoverInitializedNameError = this.lookahead;
var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
value = this.finalize(node, new Node.AssignmentPattern(id, init));
this.throwUnexpectedToken(this.nextToken());
return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
Parser.prototype.parseObjectInitializer = function () {
var node = this.createNode();
var hasProto = { value: false };
while (!this.match('}')) {
properties.push(this.parseObjectProperty(hasProto));
this.expectCommaSeparator();
return this.finalize(node, new Node.ObjectExpression(properties));
// https://tc39.github.io/ecma262/#sec-template-literals
Parser.prototype.parseTemplateHead = function () {
assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
var node = this.createNode();
var token = this.nextToken();
var cooked = token.cooked;
return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
Parser.prototype.parseTemplateElement = function () {
if (this.lookahead.type !== 10 /* Template */) {
this.throwUnexpectedToken();
var node = this.createNode();
var token = this.nextToken();
var cooked = token.cooked;
return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
Parser.prototype.parseTemplateLiteral = function () {
var node = this.createNode();
var quasi = this.parseTemplateHead();
expressions.push(this.parseExpression());
quasi = this.parseTemplateElement();
return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
// https://tc39.github.io/ecma262/#sec-grouping-operator
Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
case syntax_1.Syntax.Identifier:
case syntax_1.Syntax.MemberExpression:
case syntax_1.Syntax.RestElement:
case syntax_1.Syntax.AssignmentPattern:
case syntax_1.Syntax.SpreadElement:
expr.type = syntax_1.Syntax.RestElement;
this.reinterpretExpressionAsPattern(expr.argument);
case syntax_1.Syntax.ArrayExpression:
expr.type = syntax_1.Syntax.ArrayPattern;
for (var i = 0; i < expr.elements.length; i++) {
if (expr.elements[i] !== null) {
this.reinterpretExpressionAsPattern(expr.elements[i]);
case syntax_1.Syntax.ObjectExpression:
expr.type = syntax_1.Syntax.ObjectPattern;
for (var i = 0; i < expr.properties.length; i++) {
this.reinterpretExpressionAsPattern(expr.properties[i].value);
case syntax_1.Syntax.AssignmentExpression:
expr.type = syntax_1.Syntax.AssignmentPattern;
this.reinterpretExpressionAsPattern(expr.left);
// Allow other node type for tolerant parsing.
Parser.prototype.parseGroupExpression = function () {
type: ArrowParameterPlaceHolder,
var startToken = this.lookahead;
expr = this.parseRestElement(params);
type: ArrowParameterPlaceHolder,
this.context.isBindingElement = true;
expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
this.context.isAssignmentTarget = false;
while (this.lookahead.type !== 2 /* EOF */) {
for (var i = 0; i < expressions.length; i++) {
this.reinterpretExpressionAsPattern(expressions[i]);
type: ArrowParameterPlaceHolder,
else if (this.match('...')) {
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
expressions.push(this.parseRestElement(params));
this.context.isBindingElement = false;
for (var i = 0; i < expressions.length; i++) {
this.reinterpretExpressionAsPattern(expressions[i]);
type: ArrowParameterPlaceHolder,
expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
type: ArrowParameterPlaceHolder,
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
if (expr.type === syntax_1.Syntax.SequenceExpression) {
for (var i = 0; i < expr.expressions.length; i++) {
this.reinterpretExpressionAsPattern(expr.expressions[i]);
this.reinterpretExpressionAsPattern(expr);
var parameters = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
type: ArrowParameterPlaceHolder,
this.context.isBindingElement = false;
// https://tc39.github.io/ecma262/#sec-left-hand-side-expressions
Parser.prototype.parseArguments = function () {
var expr = this.match('...') ? this.parseSpreadElement() :
this.isolateCoverGrammar(this.parseAssignmentExpression);
this.expectCommaSeparator();
Parser.prototype.isIdentifierName = function (token) {
return token.type === 3 /* Identifier */ ||
token.type === 4 /* Keyword */ ||
token.type === 1 /* BooleanLiteral */ ||
token.type === 5 /* NullLiteral */;
Parser.prototype.parseIdentifierName = function () {
var node = this.createNode();
var token = this.nextToken();
if (!this.isIdentifierName(token)) {
this.throwUnexpectedToken(token);
return this.finalize(node, new Node.Identifier(token.value));
Parser.prototype.parseNewExpression = function () {
var node = this.createNode();
var id = this.parseIdentifierName();
assert_1.assert(id.name === 'new', 'New expression must start with `new`');
if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') {
var property = this.parseIdentifierName();
expr = new Node.MetaProperty(id, property);
this.throwUnexpectedToken(this.lookahead);
var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
var args = this.match('(') ? this.parseArguments() : [];
expr = new Node.NewExpression(callee, args);
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
return this.finalize(node, expr);
Parser.prototype.parseAsyncArgument = function () {
var arg = this.parseAssignmentExpression();
this.context.firstCoverInitializedNameError = null;
Parser.prototype.parseAsyncArguments = function () {
var expr = this.match('...') ? this.parseSpreadElement() :
this.isolateCoverGrammar(this.parseAsyncArgument);
this.expectCommaSeparator();
Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
var startToken = this.lookahead;
var maybeAsync = this.matchContextualKeyword('async');
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
if (this.matchKeyword('super') && this.context.inFunctionBody) {
expr = this.createNode();
expr = this.finalize(expr, new Node.Super());
if (!this.match('(') && !this.match('.') && !this.match('[')) {
this.throwUnexpectedToken(this.lookahead);
expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
var property = this.parseIdentifierName();
expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
else if (this.match('(')) {
var asyncArrow = maybeAsync && (startToken.lineNumber === this.lookahead.lineNumber);
this.context.isBindingElement = false;
this.context.isAssignmentTarget = false;
var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments();
expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
if (asyncArrow && this.match('=>')) {
for (var i = 0; i < args.length; ++i) {
this.reinterpretExpressionAsPattern(args[i]);
type: ArrowParameterPlaceHolder,
else if (this.match('[')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
var property = this.isolateCoverGrammar(this.parseExpression);
expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
this.context.allowIn = previousAllowIn;
Parser.prototype.parseSuper = function () {
var node = this.createNode();
this.expectKeyword('super');
if (!this.match('[') && !this.match('.')) {
this.throwUnexpectedToken(this.lookahead);
return this.finalize(node, new Node.Super());
Parser.prototype.parseLeftHandSideExpression = function () {
assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
var node = this.startNode(this.lookahead);
var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
var property = this.isolateCoverGrammar(this.parseExpression);
expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
else if (this.match('.')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
var property = this.parseIdentifierName();
expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
// https://tc39.github.io/ecma262/#sec-update-expressions
Parser.prototype.parseUpdateExpression = function () {
var startToken = this.lookahead;
if (this.match('++') || this.match('--')) {
var node = this.startNode(startToken);
var token = this.nextToken();
expr = this.inheritCoverGrammar(this.parseUnaryExpression);
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
this.tolerateError(messages_1.Messages.StrictLHSPrefix);
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) {
if (this.match('++') || this.match('--')) {
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {