diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index c8773f9bbe2a..54e9919fb0aa 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -381,14 +381,8 @@ export default class Tokenizer extends LocationParser { } if ( - (this.hasPlugin("classPrivateProperties") || - this.hasPlugin("classPrivateMethods")) && - this.state.classLevel > 0 - ) { - ++this.state.pos; - this.finishToken(tt.hash); - return; - } else if ( + this.hasPlugin("classPrivateProperties") || + this.hasPlugin("classPrivateMethods") || this.getPluginOption("pipelineOperator", "proposal") === "smart" ) { this.finishOp(tt.hash, 1); diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json index 9682fa229092..1a24d82b0b75 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json @@ -1,4 +1,4 @@ { "plugins": ["classPrivateProperties"], - "throws": "Unexpected character '#' (1:15)" + "throws": "Private name #priv is not defined (1:15)" } \ No newline at end of file