Skip to content

Commit

Permalink
refactor: remove unused invalidTemplateEscapePosition tokenizer state (
Browse files Browse the repository at this point in the history
…#10935)

* refactor: remove unused invalidTemplateEscapePosition tokenizer state

* fix flow error
  • Loading branch information
JLHwung committed Dec 30, 2019
1 parent 30449fe commit 2f3f779
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
8 changes: 1 addition & 7 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -1430,13 +1430,7 @@ export default class ExpressionParser extends LValParser {
const elem = this.startNode();
if (this.state.value === null) {
if (!isTagged) {
// TODO: fix this
this.raise(
this.state.invalidTemplateEscapePosition || 0,
"Invalid escape sequence in template",
);
} else {
this.state.invalidTemplateEscapePosition = null;
this.raise(this.state.start + 1, "Invalid escape sequence in template");
}
}
elem.value = {
Expand Down
11 changes: 1 addition & 10 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -1122,14 +1122,10 @@ export default class Tokenizer extends LocationParser {
throwOnInvalid,
);
++this.state.pos;
if (code === null) {
// $FlowFixMe (is this always non-null?)
--this.state.invalidTemplateEscapePosition; // to point to the '\'' instead of the 'u'
} else if (code > 0x10ffff) {
if (code !== null && code > 0x10ffff) {
if (throwOnInvalid) {
this.raise(codePos, "Code point out of bounds");
} else {
this.state.invalidTemplateEscapePosition = codePos - 2;
return null;
}
}
Expand Down Expand Up @@ -1274,9 +1270,6 @@ export default class Tokenizer extends LocationParser {
case charCodes.digit8:
case charCodes.digit9:
if (inTemplate) {
const codePos = this.state.pos - 1;

this.state.invalidTemplateEscapePosition = codePos;
return null;
}
default:
Expand All @@ -1299,7 +1292,6 @@ export default class Tokenizer extends LocationParser {
next === charCodes.digit9
) {
if (inTemplate) {
this.state.invalidTemplateEscapePosition = codePos;
return null;
} else if (this.state.strict) {
this.raise(codePos, "Octal literal in strict mode");
Expand Down Expand Up @@ -1332,7 +1324,6 @@ export default class Tokenizer extends LocationParser {
this.raise(codePos, "Bad character escape sequence");
} else {
this.state.pos = codePos - 1;
this.state.invalidTemplateEscapePosition = codePos - 1;
}
}
return n;
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-parser/src/tokenizer/state.js
Expand Up @@ -156,8 +156,6 @@ export default class State {
// `export default foo;` and `export { foo as default };`.
exportedIdentifiers: Array<string> = [];

invalidTemplateEscapePosition: ?number = null;

curPosition(): Position {
return new Position(this.curLine, this.pos - this.lineStart);
}
Expand Down

0 comments on commit 2f3f779

Please sign in to comment.