: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
var declaration = this.parseFunctionDeclaration();
if (this.context.strict) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction);
else if (declaration.generator) {
this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext);
body = this.parseStatement();
delete this.context.labelSet[key];
statement = new Node.LabeledStatement(id, body);
statement = new Node.ExpressionStatement(expr);
return this.finalize(node, statement);
// https://tc39.github.io/ecma262/#sec-throw-statement
Parser.prototype.parseThrowStatement = function () {
var node = this.createNode();
this.expectKeyword('throw');
if (this.hasLineTerminator) {
this.throwError(messages_1.Messages.NewlineAfterThrow);
var argument = this.parseExpression();
return this.finalize(node, new Node.ThrowStatement(argument));
// https://tc39.github.io/ecma262/#sec-try-statement
Parser.prototype.parseCatchClause = function () {
var node = this.createNode();
this.expectKeyword('catch');
this.throwUnexpectedToken(this.lookahead);
var param = this.parsePattern(params);
for (var i = 0; i < params.length; i++) {
var key = '$' + params[i].value;
if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord(param.name)) {
this.tolerateError(messages_1.Messages.StrictCatchVariable);
var body = this.parseBlock();
return this.finalize(node, new Node.CatchClause(param, body));
Parser.prototype.parseFinallyClause = function () {
this.expectKeyword('finally');
return this.parseBlock();
Parser.prototype.parseTryStatement = function () {
var node = this.createNode();
this.expectKeyword('try');
var block = this.parseBlock();
var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
if (!handler && !finalizer) {
this.throwError(messages_1.Messages.NoCatchOrFinally);
return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
// https://tc39.github.io/ecma262/#sec-debugger-statement
Parser.prototype.parseDebuggerStatement = function () {
var node = this.createNode();
this.expectKeyword('debugger');
return this.finalize(node, new Node.DebuggerStatement());
// https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations
Parser.prototype.parseStatement = function () {
switch (this.lookahead.type) {
case 1 /* BooleanLiteral */:
case 5 /* NullLiteral */:
case 6 /* NumericLiteral */:
case 8 /* StringLiteral */:
case 9 /* RegularExpression */:
statement = this.parseExpressionStatement();
var value = this.lookahead.value;
statement = this.parseBlock();
else if (value === '(') {
statement = this.parseExpressionStatement();
else if (value === ';') {
statement = this.parseEmptyStatement();
statement = this.parseExpressionStatement();
statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
switch (this.lookahead.value) {
statement = this.parseBreakStatement();
statement = this.parseContinueStatement();
statement = this.parseDebuggerStatement();
statement = this.parseDoWhileStatement();
statement = this.parseForStatement();
statement = this.parseFunctionDeclaration();
statement = this.parseIfStatement();
statement = this.parseReturnStatement();
statement = this.parseSwitchStatement();
statement = this.parseThrowStatement();
statement = this.parseTryStatement();
statement = this.parseVariableStatement();
statement = this.parseWhileStatement();
statement = this.parseWithStatement();
statement = this.parseExpressionStatement();
statement = this.throwUnexpectedToken(this.lookahead);
// https://tc39.github.io/ecma262/#sec-function-definitions
Parser.prototype.parseFunctionSourceElements = function () {
var node = this.createNode();
var body = this.parseDirectivePrologues();
var previousLabelSet = this.context.labelSet;
var previousInIteration = this.context.inIteration;
var previousInSwitch = this.context.inSwitch;
var previousInFunctionBody = this.context.inFunctionBody;
this.context.labelSet = {};
this.context.inIteration = false;
this.context.inSwitch = false;
this.context.inFunctionBody = true;
while (this.lookahead.type !== 2 /* EOF */) {
body.push(this.parseStatementListItem());
this.context.labelSet = previousLabelSet;
this.context.inIteration = previousInIteration;
this.context.inSwitch = previousInSwitch;
this.context.inFunctionBody = previousInFunctionBody;
return this.finalize(node, new Node.BlockStatement(body));
Parser.prototype.validateParam = function (options, param, name) {
if (this.context.strict) {
if (this.scanner.isRestrictedWord(name)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamName;
if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
else if (!options.firstRestricted) {
if (this.scanner.isRestrictedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictParamName;
else if (this.scanner.isStrictModeReservedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictReservedWord;
else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
/* istanbul ignore next */
if (typeof Object.defineProperty === 'function') {
Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
options.paramSet[key] = true;
Parser.prototype.parseRestElement = function (params) {
var node = this.createNode();
var arg = this.parsePattern(params);
this.throwError(messages_1.Messages.DefaultRestParameter);
this.throwError(messages_1.Messages.ParameterAfterRestParameter);
return this.finalize(node, new Node.RestElement(arg));
Parser.prototype.parseFormalParameter = function (options) {
var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
for (var i = 0; i < params.length; i++) {
this.validateParam(options, params[i], params[i].value);
options.simple = options.simple && (param instanceof Node.Identifier);
options.params.push(param);
Parser.prototype.parseFormalParameters = function (firstRestricted) {
firstRestricted: firstRestricted
while (this.lookahead.type !== 2 /* EOF */) {
this.parseFormalParameter(options);
stricted: options.stricted,
firstRestricted: options.firstRestricted,
Parser.prototype.matchAsyncFunction = function () {
var match = this.matchContextualKeyword('async');
var state = this.scanner.saveState();
this.scanner.scanComments();
var next = this.scanner.lex();
this.scanner.restoreState(state);
match = (state.lineNumber === next.lineNumber) && (next.type === 4 /* Keyword */) && (next.value === 'function');
Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
var node = this.createNode();
var isAsync = this.matchContextualKeyword('async');
this.expectKeyword('function');
var isGenerator = isAsync ? false : this.match('*');
var firstRestricted = null;
if (!identifierIsOptional || !this.match('(')) {
var token = this.lookahead;
id = this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
if (this.scanner.isRestrictedWord(token.value)) {
message = messages_1.Messages.StrictFunctionName;
else if (this.scanner.isStrictModeReservedWord(token.value)) {
message = messages_1.Messages.StrictReservedWord;
var previousAllowAwait = this.context.await;
var previousAllowYield = this.context.allowYield;
this.context.await = isAsync;
this.context.allowYield = !isGenerator;
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = formalParameters.simple;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
this.context.await = previousAllowAwait;
this.context.allowYield = previousAllowYield;
return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) :
this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
Parser.prototype.parseFunctionExpression = function () {
var node = this.createNode();
var isAsync = this.matchContextualKeyword('async');
this.expectKeyword('function');
var isGenerator = isAsync ? false : this.match('*');
var previousAllowAwait = this.context.await;
var previousAllowYield = this.context.allowYield;
this.context.await = isAsync;
this.context.allowYield = !isGenerator;
var token = this.lookahead;
id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
if (this.scanner.isRestrictedWord(token.value)) {
message = messages_1.Messages.StrictFunctionName;
else if (this.scanner.isStrictModeReservedWord(token.value)) {
message = messages_1.Messages.StrictReservedWord;
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = formalParameters.simple;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
this.context.await = previousAllowAwait;
this.context.allowYield = previousAllowYield;
return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) :
this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
// https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive
Parser.prototype.parseDirective = function () {
var token = this.lookahead;
var node = this.createNode();
var expr = this.parseExpression();
var directive = (expr.type === syntax_1.Syntax.Literal) ? this.getTokenRaw(token).slice(1, -1) : null;
return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr));
Parser.prototype.parseDirectivePrologues = function () {
var firstRestricted = null;
var token = this.lookahead;
if (token.type !== 8 /* StringLiteral */) {
var statement = this.parseDirective();
var directive = statement.directive;
if (typeof directive !== 'string') {
if (directive === 'use strict') {
this.context.strict = true;
this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
if (!this.context.allowStrictDirective) {
this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective);
if (!firstRestricted && token.octal) {
// https://tc39.github.io/ecma262/#sec-method-definitions
Parser.prototype.qualifiedPropertyName = function (token) {
case 8 /* StringLiteral */:
case 1 /* BooleanLiteral */:
case 5 /* NullLiteral */:
case 6 /* NumericLiteral */:
return token.value === '[';
Parser.prototype.parseGetterMethod = function () {
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var formalParameters = this.parseFormalParameters();
if (formalParameters.params.length > 0) {
this.tolerateError(messages_1.Messages.BadGetterArity);
var method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
Parser.prototype.parseSetterMethod = function () {
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var formalParameters = this.parseFormalParameters();
if (formalParameters.params.length !== 1) {
this.tolerateError(messages_1.Messages.BadSetterArity);
else if (formalParameters.params[0] instanceof Node.RestElement) {
this.tolerateError(messages_1.Messages.BadSetterRestParameter);
var method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
Parser.prototype.parseGeneratorMethod = function () {
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;