fix(45114): throw an error when using '#' as an identifier (#45124)
This commit is contained in:
parent
ba226167bc
commit
11c7daef62
|
@ -2047,8 +2047,15 @@ namespace ts {
|
||||||
pos++;
|
pos++;
|
||||||
return token = SyntaxKind.Unknown;
|
return token = SyntaxKind.Unknown;
|
||||||
}
|
}
|
||||||
pos++;
|
|
||||||
scanIdentifier(codePointAt(text, pos), languageVersion);
|
if (isIdentifierStart(codePointAt(text, pos + 1), languageVersion)) {
|
||||||
|
pos++;
|
||||||
|
scanIdentifier(codePointAt(text, pos), languageVersion);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tokenValue = String.fromCharCode(codePointAt(text, pos));
|
||||||
|
error(Diagnostics.Invalid_character, pos++, charSize(ch));
|
||||||
|
}
|
||||||
return token = SyntaxKind.PrivateIdentifier;
|
return token = SyntaxKind.PrivateIdentifier;
|
||||||
default:
|
default:
|
||||||
const identifierKind = scanIdentifier(ch, languageVersion);
|
const identifierKind = scanIdentifier(ch, languageVersion);
|
||||||
|
|
25
tests/baselines/reference/privateNameHashCharName.errors.txt
Normal file
25
tests/baselines/reference/privateNameHashCharName.errors.txt
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts(1,1): error TS1127: Invalid character.
|
||||||
|
tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts(1,1): error TS2304: Cannot find name '#'.
|
||||||
|
tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts(4,5): error TS1127: Invalid character.
|
||||||
|
tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts(7,14): error TS1127: Invalid character.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts (4 errors) ====
|
||||||
|
#
|
||||||
|
~
|
||||||
|
!!! error TS1127: Invalid character.
|
||||||
|
~
|
||||||
|
!!! error TS2304: Cannot find name '#'.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
#
|
||||||
|
~
|
||||||
|
!!! error TS1127: Invalid character.
|
||||||
|
|
||||||
|
m() {
|
||||||
|
this.#
|
||||||
|
~
|
||||||
|
!!! error TS1127: Invalid character.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
29
tests/baselines/reference/privateNameHashCharName.js
Normal file
29
tests/baselines/reference/privateNameHashCharName.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
//// [privateNameHashCharName.ts]
|
||||||
|
#
|
||||||
|
|
||||||
|
class C {
|
||||||
|
#
|
||||||
|
|
||||||
|
m() {
|
||||||
|
this.#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// [privateNameHashCharName.js]
|
||||||
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||||
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||||
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||||
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||||
|
};
|
||||||
|
var _C_;
|
||||||
|
#;
|
||||||
|
class C {
|
||||||
|
constructor() {
|
||||||
|
_C_.set(this, void 0);
|
||||||
|
}
|
||||||
|
m() {
|
||||||
|
__classPrivateFieldGet(this, _C_, "f");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_C_ = new WeakMap();
|
18
tests/baselines/reference/privateNameHashCharName.symbols
Normal file
18
tests/baselines/reference/privateNameHashCharName.symbols
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
=== tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts ===
|
||||||
|
#
|
||||||
|
|
||||||
|
class C {
|
||||||
|
>C : Symbol(C, Decl(privateNameHashCharName.ts, 0, 1))
|
||||||
|
|
||||||
|
#
|
||||||
|
># : Symbol(C[#], Decl(privateNameHashCharName.ts, 2, 9))
|
||||||
|
|
||||||
|
m() {
|
||||||
|
>m : Symbol(C.m, Decl(privateNameHashCharName.ts, 3, 5))
|
||||||
|
|
||||||
|
this.#
|
||||||
|
>this.# : Symbol(C[#], Decl(privateNameHashCharName.ts, 2, 9))
|
||||||
|
>this : Symbol(C, Decl(privateNameHashCharName.ts, 0, 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
19
tests/baselines/reference/privateNameHashCharName.types
Normal file
19
tests/baselines/reference/privateNameHashCharName.types
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
=== tests/cases/conformance/classes/members/privateNames/privateNameHashCharName.ts ===
|
||||||
|
#
|
||||||
|
># : any
|
||||||
|
|
||||||
|
class C {
|
||||||
|
>C : C
|
||||||
|
|
||||||
|
#
|
||||||
|
># : any
|
||||||
|
|
||||||
|
m() {
|
||||||
|
>m : () => void
|
||||||
|
|
||||||
|
this.#
|
||||||
|
>this.# : any
|
||||||
|
>this : this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// @target: es6
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
class C {
|
||||||
|
#
|
||||||
|
|
||||||
|
m() {
|
||||||
|
this.#
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue