Skip to content

Commit

Permalink
Fix error message for babel#4 case
Browse files Browse the repository at this point in the history
This impact private fields as well as smart pipeline, providing a clearer
error message for both.
  • Loading branch information
mAAdhaTTah committed Aug 10, 2018
1 parent ba5642d commit 25d0146
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
15 changes: 5 additions & 10 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -412,6 +412,10 @@ export default class Tokenizer extends LocationParser {

const nextPos = this.state.pos + 1;
const next = this.input.charCodeAt(nextPos);
if (next >= charCodes.digit0 && next <= charCodes.digit9) {
this.raise(this.state.pos, "Unexpected digit after hash token");
}

if (
(this.hasPlugin("classPrivateProperties") ||
this.hasPlugin("classPrivateMethods")) &&
Expand All @@ -423,16 +427,7 @@ export default class Tokenizer extends LocationParser {
} else if (
this.getPluginOption("pipelineOperator", "proposal") === "smart"
) {
if (next >= charCodes.digit0 && next <= charCodes.digit9) {
this.raise(
this.state.pos,
`Unexpected digit after topic reference: '#${String.fromCodePoint(
next,
)}'`,
);
} else {
this.finishOp(tt.hash, 1);
}
this.finishOp(tt.hash, 1);
} else {
this.raise(
this.state.pos,
Expand Down
@@ -1,4 +1,4 @@
{
"throws": "Unexpected token (2:3)",
"throws": "Unexpected digit after hash token (2:2)",
"plugins": [ "classPrivateProperties" ]
}
@@ -1,4 +1,4 @@
{
"throws": "Identifier directly after number (2:4)",
"throws": "Unexpected digit after hash token (2:2)",
"plugins": ["classPrivateProperties"]
}
@@ -1,4 +1,4 @@
{
"plugins": [["pipelineOperator", { "proposal": "smart" }]],
"throws": "Unexpected digit after topic reference: '#4' (1:5)"
"throws": "Unexpected digit after hash token (1:5)"
}

0 comments on commit 25d0146

Please sign in to comment.