diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 138e79d9c2..2c362e0c24 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -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")) && @@ -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, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json index dfd75111a5..03592e655a 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json @@ -1,4 +1,4 @@ { - "throws": "Unexpected token (2:3)", + "throws": "Unexpected digit after hash token (2:2)", "plugins": [ "classPrivateProperties" ] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json index c1de1d488c..2ba960820f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json @@ -1,4 +1,4 @@ { - "throws": "Identifier directly after number (2:4)", + "throws": "Unexpected digit after hash token (2:2)", "plugins": ["classPrivateProperties"] } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json index 6d423c8c9d..a2f6f625f9 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json @@ -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)" }