Skip to content

Commit

Permalink
fix(babel-parser): Move storage of expressionValue in DirectiveLitera…
Browse files Browse the repository at this point in the history
…l to main parser so it is accessible to others.

Closes #13953.

Reviewed by @tolmasky.
  • Loading branch information
tolmasky committed Nov 13, 2021
1 parent f731522 commit 715e9e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -157,13 +157,17 @@ export default class StatementParser extends ExpressionParser {
directive.value = directive.expression;
delete directive.expression;

const expressionValue = directiveLiteral.value;
const directiveLiteral = directive.value;
const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes

this.addExtra(directiveLiteral, "raw", raw);
this.addExtra(directiveLiteral, "rawValue", val);
this.addExtra(directiveLiteral, "expressionValue", expressionValue);

directiveLiteral.type = "DirectiveLiteral";

return directive;
}

Expand Down
12 changes: 0 additions & 12 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -130,18 +130,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}

stmtToDirective(stmt: N.Statement): N.Directive {
const value = stmt.expression.value;
const directive = super.stmtToDirective(stmt);

// Record the expression value as in estree mode we want
// the stmt to have the real value e.g. ("use strict") and
// not the raw value e.g. ("use\\x20strict")
this.addExtra(directive.value, "expressionValue", value);

return directive;
}

parseBlockBody(
node: N.BlockStatementLike,
...args: [?boolean, boolean, TokenType, void | (boolean => void)]
Expand Down

0 comments on commit 715e9e9

Please sign in to comment.