diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0d6a91def8c..eae59db1bc6 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3697,13 +3697,13 @@ namespace ts { break; case SyntaxKind.NumericLiteral: - const flags = (node).numericLiteralFlags; - if (flags & TokenFlags.BinaryOrOctalSpecifier) { + if ((node).numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) { transformFlags |= TransformFlags.AssertES2015; } - if (flags & TokenFlags.BigInt) { - transformFlags |= TransformFlags.AssertESNext; - } + break; + + case SyntaxKind.BigIntLiteral: + transformFlags |= TransformFlags.AssertESNext; break; case SyntaxKind.ForOfStatement: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0353b21869d..a16cab1443c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9268,18 +9268,11 @@ namespace ts { type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false)); } - function getNumericLiteralValue(node: NumericLiteral): number | PseudoBigInt { - if (node.numericLiteralFlags & TokenFlags.BigInt) { - if (!compilerOptions.experimentalBigInt) { - error(node, Diagnostics.Experimental_support_for_BigInt_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalBigInt_option_to_remove_this_warning); - } - return { negative: false, base10Value: parsePseudoBigInt(node.text) }; - } - return +node.text; - } - - function getNumericLiteralType(node: NumericLiteral): LiteralType { - return getLiteralType(getNumericLiteralValue(node)); + function getBigIntLiteralType(node: BigIntLiteral): LiteralType { + return getLiteralType({ + negative: false, + base10Value: parsePseudoBigInt(node.text) + }); } function getLiteralTypeFromPropertyName(prop: Symbol, include: TypeFlags) { @@ -9287,8 +9280,8 @@ namespace ts { let type = getLateBoundSymbol(prop).nameType; if (!type && !isKnownSymbol(prop)) { const name = prop.valueDeclaration && getNameOfDeclaration(prop.valueDeclaration); - type = name && isNumericLiteral(name) ? getNumericLiteralType(name) : - name && name.kind === SyntaxKind.ComputedPropertyName && isNumericLiteral(name.expression) ? getNumericLiteralType(name.expression) : + type = name && isNumericLiteral(name) ? getLiteralType(+name.text) : + name && name.kind === SyntaxKind.ComputedPropertyName && isNumericLiteral(name.expression) ? getLiteralType(+name.expression.text) : getLiteralType(symbolName(prop)); } if (type && type.flags & include) { @@ -17077,6 +17070,7 @@ namespace ts { switch (node.kind) { case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: @@ -21503,22 +21497,22 @@ namespace ts { if (operandType === silentNeverType) { return silentNeverType; } - if (node.operand.kind === SyntaxKind.NumericLiteral) { - if (node.operator === SyntaxKind.MinusToken) { - const value = getNumericLiteralValue(node.operand as NumericLiteral); - return getFreshTypeOfLiteralType(getLiteralType( - // Keep number as number, bigint as bigint - typeof value === "number" - ? -value - : { negative: !value.negative, base10Value: value.base10Value } - )); - } - else if (node.operator === SyntaxKind.PlusToken) { - if (isTypeAssignableToKind(operandType, TypeFlags.BigIntLike)) { - error(node.operand, Diagnostics.Operator_0_cannot_be_applied_to_type_1, tokenToString(node.operator), typeToString(operandType)); + switch (node.operand.kind) { + case SyntaxKind.NumericLiteral: + switch (node.operator) { + case SyntaxKind.MinusToken: + return getFreshTypeOfLiteralType(getLiteralType(-(node.operand as NumericLiteral).text)); + case SyntaxKind.PlusToken: + return getFreshTypeOfLiteralType(getLiteralType(+(node.operand as NumericLiteral).text)); + } + break; + case SyntaxKind.BigIntLiteral: + if (node.operator === SyntaxKind.MinusToken) { + return getFreshTypeOfLiteralType(getLiteralType({ + negative: true, + base10Value: parsePseudoBigInt((node.operand as BigIntLiteral).text) + })); } - return getFreshTypeOfLiteralType(getNumericLiteralType(node.operand as NumericLiteral)); - } } switch (node.operator) { case SyntaxKind.PlusToken: @@ -21860,6 +21854,7 @@ namespace ts { case SyntaxKind.TemplateExpression: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: case SyntaxKind.NullKeyword: @@ -22002,7 +21997,6 @@ namespace ts { } return resultType; } - case SyntaxKind.PlusToken: case SyntaxKind.PlusEqualsToken: if (leftType === silentNeverType || rightType === silentNeverType) { @@ -22558,7 +22552,10 @@ namespace ts { return getFreshTypeOfLiteralType(getLiteralType((node as StringLiteralLike).text)); case SyntaxKind.NumericLiteral: checkGrammarNumericLiteral(node as NumericLiteral); - return getFreshTypeOfLiteralType(getNumericLiteralType(node as NumericLiteral)); + return getFreshTypeOfLiteralType(getLiteralType(+(node as NumericLiteral).text)); + case SyntaxKind.BigIntLiteral: + checkGrammarBigIntLiteral(node as BigIntLiteral); + return getFreshTypeOfLiteralType(getBigIntLiteralType(node as BigIntLiteral)); case SyntaxKind.TrueKeyword: return trueType; case SyntaxKind.FalseKeyword: @@ -26595,8 +26592,7 @@ namespace ts { return (expr).text; case SyntaxKind.NumericLiteral: checkGrammarNumericLiteral(expr); - const literalValue = getNumericLiteralValue(expr); - return typeof literalValue === "number" ? literalValue : undefined; // don't evaluate bigint + return +(expr).text; case SyntaxKind.ParenthesizedExpression: return evaluate((expr).expression); case SyntaxKind.Identifier: @@ -30462,6 +30458,18 @@ namespace ts { return false; } + function checkGrammarBigIntLiteral(node: BigIntLiteral): boolean { + if (languageVersion < ScriptTarget.ESNext) { + if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targetting_lower_than_ESNext)) { + return true; + } + } + if (!compilerOptions.experimentalBigInt) { + return grammarErrorOnNode(node, Diagnostics.Experimental_support_for_BigInt_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalBigInt_option_to_remove_this_warning); + } + return false; + } + function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { const sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 9c333f2cadf..3947ef51844 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -588,7 +588,7 @@ namespace ts { name: "experimentalBigInt", type: "boolean", category: Diagnostics.Experimental_Options, - description: Diagnostics.Enables_experimental_support_for_ESNext_BigInt_expressions + description: Diagnostics.Enables_experimental_support_for_ESNext_BigInt_literals }, // Advanced diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a1cab6bfaff..49f682c4d58 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2505,6 +2505,10 @@ "category": "Error", "code": 2736 }, + "BigInt literals are not available when targetting lower than ESNext.": { + "category": "Error", + "code": 2737 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -3913,7 +3917,7 @@ "category": "Error", "code": 6370 }, - "Enables experimental support for ESNext BigInt expressions.": { + "Enables experimental support for ESNext BigInt literals.": { "category": "Message", "code": 6371 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 50644552efe..2443f72d591 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -905,7 +905,8 @@ namespace ts { switch (node.kind) { // Literals case SyntaxKind.NumericLiteral: - return emitNumericLiteral(node); + case SyntaxKind.BigIntLiteral: + return emitNumericOrBigIntLiteral(node); case SyntaxKind.StringLiteral: case SyntaxKind.RegularExpressionLiteral: @@ -1068,7 +1069,8 @@ namespace ts { // // SyntaxKind.NumericLiteral - function emitNumericLiteral(node: NumericLiteral) { + // SyntaxKind.BigIntLiteral + function emitNumericOrBigIntLiteral(node: NumericLiteral | BigIntLiteral) { emitLiteral(node); } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 39d3d5c3c83..160376c39b2 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -76,9 +76,7 @@ namespace ts { return createNumericLiteral(value + ""); } if (typeof value === "object" && "base10Value" in value) { // PseudoBigInt - const literal = createNumericLiteral(pseudoBigIntToString(value) + "n"); - literal.numericLiteralFlags |= TokenFlags.BigInt; - return literal; + return createBigIntLiteral(pseudoBigIntToString(value) + "n"); } if (typeof value === "boolean") { return value ? createTrue() : createFalse(); @@ -98,6 +96,12 @@ namespace ts { return node; } + export function createBigIntLiteral(value: string): BigIntLiteral { + const node = createSynthesizedNode(SyntaxKind.BigIntLiteral); + node.text = value; + return node; + } + export function createStringLiteral(text: string): StringLiteral { const node = createSynthesizedNode(SyntaxKind.StringLiteral); node.text = text; @@ -3472,6 +3476,7 @@ namespace ts { return cacheIdentifiers; case SyntaxKind.ThisKeyword: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: return false; case SyntaxKind.ArrayLiteralExpression: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 376afe43d2c..6831d27db9c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2891,8 +2891,9 @@ namespace ts { return finishNode(node); } - function nextTokenIsNumericLiteral() { - return nextToken() === SyntaxKind.NumericLiteral; + function nextTokenIsNumericOrBigIntLiteral() { + nextToken(); + return token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.BigIntLiteral; } function parseNonArrayType(): TypeNode { @@ -2922,11 +2923,12 @@ namespace ts { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: return parseLiteralTypeNode(); case SyntaxKind.MinusToken: - return lookAhead(nextTokenIsNumericLiteral) ? parseLiteralTypeNode(/*negative*/ true) : parseTypeReference(); + return lookAhead(nextTokenIsNumericOrBigIntLiteral) ? parseLiteralTypeNode(/*negative*/ true) : parseTypeReference(); case SyntaxKind.VoidKeyword: case SyntaxKind.NullKeyword: return parseTokenNode(); @@ -2978,6 +2980,7 @@ namespace ts { case SyntaxKind.NewKeyword: case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: case SyntaxKind.ObjectKeyword: @@ -2991,7 +2994,7 @@ namespace ts { case SyntaxKind.FunctionKeyword: return !inStartOfParameter; case SyntaxKind.MinusToken: - return !inStartOfParameter && lookAhead(nextTokenIsNumericLiteral); + return !inStartOfParameter && lookAhead(nextTokenIsNumericOrBigIntLiteral); case SyntaxKind.OpenParenToken: // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, // or something that starts a type. We don't want to consider things like '(1)' a type. @@ -3216,6 +3219,7 @@ namespace ts { case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TemplateHead: @@ -4625,6 +4629,7 @@ namespace ts { function parsePrimaryExpression(): PrimaryExpression { switch (token()) { case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: return parseLiteralNode(); @@ -5140,7 +5145,7 @@ namespace ts { function nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine() { nextToken(); - return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.StringLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.BigIntLiteral || token() === SyntaxKind.StringLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 22b90df6799..b8d4d248077 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -920,7 +920,7 @@ namespace ts { return result + text.substring(start, pos); } - function scanNumber(): string { + function scanNumber(): {type: SyntaxKind, value: string} { const start = pos; const mainFragment = scanNumberFragment(); let decimalFragment: string | undefined; @@ -957,13 +957,16 @@ namespace ts { else { result = text.substring(start, end); // No need to use all the fragments; no _ removal needed } - if (decimalFragment === undefined && !(tokenFlags & TokenFlags.Scientific)) { - tokenValue = result; - checkBigIntSuffix(); // if value is an integer, check whether it is a bigint - return tokenValue; + if (decimalFragment !== undefined || tokenFlags & TokenFlags.Scientific) { + return { + type: SyntaxKind.NumericLiteral, + value: "" + +result // if value is not an integer, it can be safely coerced to a number + }; } else { - return "" + +result; // if value is not an integer, it can be safely coerced to a number + tokenValue = result; + const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint + return { type, value: tokenValue }; } } @@ -1354,15 +1357,15 @@ namespace ts { return value; } - function checkBigIntSuffix(): void { + function checkBigIntSuffix(): SyntaxKind { if (text.charCodeAt(pos) === CharacterCodes.n) { - tokenFlags |= TokenFlags.BigInt; tokenValue += "n"; // Use base 10 instead of base 2 or base 8 for shorter literals if (tokenFlags & TokenFlags.BinaryOrOctalSpecifier) { tokenValue = parsePseudoBigInt(tokenValue) + "n"; } pos++; + return SyntaxKind.BigIntLiteral; } else { // not a bigint, so can convert to number in simplified form // Number() may not support 0b or 0o, so use parseInt() instead @@ -1372,6 +1375,7 @@ namespace ts { ? parseInt(tokenValue.slice(2), 8) // skip "0o" : +tokenValue; tokenValue = "" + numericValue; + return SyntaxKind.NumericLiteral; } } @@ -1523,7 +1527,7 @@ namespace ts { return token = SyntaxKind.MinusToken; case CharacterCodes.dot: if (isDigit(text.charCodeAt(pos + 1))) { - tokenValue = scanNumber(); + tokenValue = scanNumber().value; return token = SyntaxKind.NumericLiteral; } if (text.charCodeAt(pos + 1) === CharacterCodes.dot && text.charCodeAt(pos + 2) === CharacterCodes.dot) { @@ -1606,8 +1610,7 @@ namespace ts { } tokenValue = "0x" + tokenValue; tokenFlags |= TokenFlags.HexSpecifier; - checkBigIntSuffix(); - return token = SyntaxKind.NumericLiteral; + return token = checkBigIntSuffix(); } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.B || text.charCodeAt(pos + 1) === CharacterCodes.b)) { pos += 2; @@ -1618,8 +1621,7 @@ namespace ts { } tokenValue = "0b" + tokenValue; tokenFlags |= TokenFlags.BinarySpecifier; - checkBigIntSuffix(); - return token = SyntaxKind.NumericLiteral; + return token = checkBigIntSuffix(); } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) { pos += 2; @@ -1630,8 +1632,7 @@ namespace ts { } tokenValue = "0o" + tokenValue; tokenFlags |= TokenFlags.OctalSpecifier; - checkBigIntSuffix(); - return token = SyntaxKind.NumericLiteral; + return token = checkBigIntSuffix(); } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { @@ -1652,8 +1653,8 @@ namespace ts { case CharacterCodes._7: case CharacterCodes._8: case CharacterCodes._9: - tokenValue = scanNumber(); - return token = SyntaxKind.NumericLiteral; + ({ type: token, value: tokenValue } = scanNumber()); + return token; case CharacterCodes.colon: pos++; return token = SyntaxKind.ColonToken; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 057dfc97a74..5917a365ddf 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1901,6 +1901,9 @@ namespace ts { case SyntaxKind.NumericLiteral: return createIdentifier("Number"); + case SyntaxKind.BigIntLiteral: + return getGlobalBigIntNameWithFallback(); + case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: return createIdentifier("Boolean"); @@ -1912,6 +1915,9 @@ namespace ts { case SyntaxKind.NumberKeyword: return createIdentifier("Number"); + case SyntaxKind.BigIntKeyword: + return getGlobalBigIntNameWithFallback(); + case SyntaxKind.SymbolKeyword: return languageVersion < ScriptTarget.ES2015 ? getGlobalSymbolNameWithFallback() @@ -2007,7 +2013,7 @@ namespace ts { return createVoidZero(); case TypeReferenceSerializationKind.BigIntLikeType: - return createIdentifier("BigInt"); + return getGlobalBigIntNameWithFallback(); case TypeReferenceSerializationKind.BooleanType: return createIdentifier("Boolean"); @@ -2118,6 +2124,20 @@ namespace ts { ); } + /** + * Gets an expression that points to the global "BigInt" constructor at runtime if it is + * available. + */ + function getGlobalBigIntNameWithFallback(): SerializedTypeNode { + return languageVersion < ScriptTarget.ESNext + ? createConditional( + createTypeCheck(createIdentifier("BigInt"), "function"), + createIdentifier("BigInt"), + createIdentifier("Object") + ) + : createIdentifier("BigInt"); + } + /** * A simple inlinable expression is an expression which can be copied into multiple locations * without risk of repeating any sideeffects and whose value could not possibly change between diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9607b95b8e3..46a5ed91275 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -129,6 +129,7 @@ namespace ts { ConflictMarkerTrivia, // Literals NumericLiteral, + BigIntLiteral, StringLiteral, JsxText, JsxTextAllWhiteSpaces, @@ -1661,9 +1662,8 @@ namespace ts { BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000` OctalSpecifier = 1 << 8, // e.g. `0o777` ContainsSeparator = 1 << 9, // e.g. `0b1100_0101` - BigInt = 1 << 10, // e.g. `123n` BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier, - NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinaryOrOctalSpecifier | ContainsSeparator | BigInt + NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinaryOrOctalSpecifier | ContainsSeparator } export interface NumericLiteral extends LiteralExpression { @@ -1672,6 +1672,10 @@ namespace ts { numericLiteralFlags: TokenFlags; } + export interface BigIntLiteral extends LiteralExpression { + kind: SyntaxKind.BigIntLiteral; + } + export interface TemplateHead extends LiteralLikeNode { kind: SyntaxKind.TemplateHead; parent: TemplateExpression; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 87795492a11..8813c705eb5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -527,7 +527,10 @@ namespace ts { export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile, neverAsciiEscape: boolean | undefined) { // If we don't need to downlevel and we can reach the original source text using // the node's parent reference, then simply get the text as it was originally written. - if (!nodeIsSynthesized(node) && node.parent && !(isNumericLiteral(node) && node.numericLiteralFlags & TokenFlags.ContainsSeparator)) { + if (!nodeIsSynthesized(node) && node.parent && !( + (isNumericLiteral(node) && node.numericLiteralFlags & TokenFlags.ContainsSeparator) || + isBigIntLiteral(node) + )) { return getSourceTextOfNodeFromSourceFile(sourceFile, node); } @@ -554,6 +557,7 @@ namespace ts { case SyntaxKind.TemplateTail: return "}" + escapeText(node.text, CharacterCodes.backtick) + "`"; case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.RegularExpressionLiteral: return node.text; } @@ -1600,6 +1604,7 @@ namespace ts { } // falls through case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.ThisKeyword: return isInExpressionContext(node); @@ -2906,6 +2911,7 @@ namespace ts { case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ObjectLiteralExpression: @@ -5272,6 +5278,10 @@ namespace ts { return node.kind === SyntaxKind.NumericLiteral; } + export function isBigIntLiteral(node: Node): node is BigIntLiteral { + return node.kind === SyntaxKind.BigIntLiteral; + } + export function isStringLiteral(node: Node): node is StringLiteral { return node.kind === SyntaxKind.StringLiteral; } @@ -6398,6 +6408,7 @@ namespace ts { case SyntaxKind.Identifier: case SyntaxKind.RegularExpressionLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TemplateExpression: @@ -8430,20 +8441,11 @@ namespace ts { } } - // TODO: remove once tslint allows tsconfig.json to include lib "esnext.bigint" - /* @internal */ - declare const BigInt: ((value: string) => number) | undefined; - /** * Converts a bigint literal string, e.g. `0x1234n`, * to its decimal string representation, e.g. `4660`. */ export function parsePseudoBigInt(stringValue: string): string { - // Use native BigInt if available - if (typeof BigInt !== "undefined") { - return "" + BigInt(stringValue.slice(0, -1)); // omit trailing "n" - } - let log2Base: number; switch (stringValue.charCodeAt(1)) { // "x" in "0x123" case CharacterCodes.b: diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index aeb2920ce3d..e4908d3612f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -4663,6 +4663,7 @@ namespace FourSlashInterface { "unknown", "from", "global", + "bigint", "of", ]; @@ -4838,6 +4839,7 @@ namespace FourSlashInterface { "unknown", "from", "global", + "bigint", "of", ]; diff --git a/src/services/classifier.ts b/src/services/classifier.ts index 5c18eae4aa1..26d77ffc602 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -182,6 +182,7 @@ namespace ts { SyntaxKind.Identifier, SyntaxKind.StringLiteral, SyntaxKind.NumericLiteral, + SyntaxKind.BigIntLiteral, SyntaxKind.RegularExpressionLiteral, SyntaxKind.ThisKeyword, SyntaxKind.PlusPlusToken, @@ -286,6 +287,7 @@ namespace ts { case ClassificationType.comment: return TokenClass.Comment; case ClassificationType.keyword: return TokenClass.Keyword; case ClassificationType.numericLiteral: return TokenClass.NumberLiteral; + case ClassificationType.bigintLiteral: return TokenClass.BigIntLiteral; case ClassificationType.operator: return TokenClass.Operator; case ClassificationType.stringLiteral: return TokenClass.StringLiteral; case ClassificationType.whiteSpace: return TokenClass.Whitespace; @@ -422,6 +424,8 @@ namespace ts { switch (token) { case SyntaxKind.NumericLiteral: return ClassificationType.numericLiteral; + case SyntaxKind.BigIntLiteral: + return ClassificationType.bigintLiteral; case SyntaxKind.StringLiteral: return ClassificationType.stringLiteral; case SyntaxKind.RegularExpressionLiteral: @@ -542,6 +546,7 @@ namespace ts { case ClassificationType.identifier: return ClassificationTypeNames.identifier; case ClassificationType.keyword: return ClassificationTypeNames.keyword; case ClassificationType.numericLiteral: return ClassificationTypeNames.numericLiteral; + case ClassificationType.bigintLiteral: return ClassificationTypeNames.bigintLiteral; case ClassificationType.operator: return ClassificationTypeNames.operator; case ClassificationType.stringLiteral: return ClassificationTypeNames.stringLiteral; case ClassificationType.whiteSpace: return ClassificationTypeNames.whiteSpace; @@ -886,6 +891,9 @@ namespace ts { else if (tokenKind === SyntaxKind.NumericLiteral) { return ClassificationType.numericLiteral; } + else if (tokenKind === SyntaxKind.BigIntLiteral) { + return ClassificationType.bigintLiteral; + } else if (tokenKind === SyntaxKind.StringLiteral) { // TODO: GH#18217 return token!.parent.kind === SyntaxKind.JsxAttribute ? ClassificationType.jsxAttributeStringLiteralValue : ClassificationType.stringLiteral; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 5e64119fcb1..b2dac950323 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -22,8 +22,8 @@ namespace ts.formatting { const binaryKeywordOperators = [SyntaxKind.InKeyword, SyntaxKind.InstanceOfKeyword, SyntaxKind.OfKeyword, SyntaxKind.AsKeyword, SyntaxKind.IsKeyword]; const unaryPrefixOperators = [SyntaxKind.PlusPlusToken, SyntaxKind.MinusMinusToken, SyntaxKind.TildeToken, SyntaxKind.ExclamationToken]; const unaryPrefixExpressions = [ - SyntaxKind.NumericLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, - SyntaxKind.OpenBraceToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]; + SyntaxKind.NumericLiteral, SyntaxKind.BigIntLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken, + SyntaxKind.OpenBracketToken, SyntaxKind.OpenBraceToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]; const unaryPreincrementExpressions = [SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]; const unaryPostincrementExpressions = [SyntaxKind.Identifier, SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken, SyntaxKind.NewKeyword]; const unaryPredecrementExpressions = [SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]; diff --git a/src/services/types.ts b/src/services/types.ts index d517c61906a..b856d15f61a 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -978,6 +978,7 @@ namespace ts { Whitespace, Identifier, NumberLiteral, + BigIntLiteral, StringLiteral, RegExpLiteral, } @@ -1141,6 +1142,7 @@ namespace ts { identifier = "identifier", keyword = "keyword", numericLiteral = "number", + bigintLiteral = "bigint", operator = "operator", stringLiteral = "string", whiteSpace = "whitespace", @@ -1189,5 +1191,6 @@ namespace ts { jsxAttribute = 22, jsxText = 23, jsxAttributeStringLiteralValue = 24, + bigintLiteral = 25, } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 30c45620c1f..61f6e6e6087 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1028,6 +1028,7 @@ namespace ts { case SyntaxKind.Identifier: case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 68113b99ca1..a6b826326cf 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -85,338 +85,339 @@ declare namespace ts { ShebangTrivia = 6, ConflictMarkerTrivia = 7, NumericLiteral = 8, - StringLiteral = 9, - JsxText = 10, - JsxTextAllWhiteSpaces = 11, - RegularExpressionLiteral = 12, - NoSubstitutionTemplateLiteral = 13, - TemplateHead = 14, - TemplateMiddle = 15, - TemplateTail = 16, - OpenBraceToken = 17, - CloseBraceToken = 18, - OpenParenToken = 19, - CloseParenToken = 20, - OpenBracketToken = 21, - CloseBracketToken = 22, - DotToken = 23, - DotDotDotToken = 24, - SemicolonToken = 25, - CommaToken = 26, - LessThanToken = 27, - LessThanSlashToken = 28, - GreaterThanToken = 29, - LessThanEqualsToken = 30, - GreaterThanEqualsToken = 31, - EqualsEqualsToken = 32, - ExclamationEqualsToken = 33, - EqualsEqualsEqualsToken = 34, - ExclamationEqualsEqualsToken = 35, - EqualsGreaterThanToken = 36, - PlusToken = 37, - MinusToken = 38, - AsteriskToken = 39, - AsteriskAsteriskToken = 40, - SlashToken = 41, - PercentToken = 42, - PlusPlusToken = 43, - MinusMinusToken = 44, - LessThanLessThanToken = 45, - GreaterThanGreaterThanToken = 46, - GreaterThanGreaterThanGreaterThanToken = 47, - AmpersandToken = 48, - BarToken = 49, - CaretToken = 50, - ExclamationToken = 51, - TildeToken = 52, - AmpersandAmpersandToken = 53, - BarBarToken = 54, - QuestionToken = 55, - ColonToken = 56, - AtToken = 57, - EqualsToken = 58, - PlusEqualsToken = 59, - MinusEqualsToken = 60, - AsteriskEqualsToken = 61, - AsteriskAsteriskEqualsToken = 62, - SlashEqualsToken = 63, - PercentEqualsToken = 64, - LessThanLessThanEqualsToken = 65, - GreaterThanGreaterThanEqualsToken = 66, - GreaterThanGreaterThanGreaterThanEqualsToken = 67, - AmpersandEqualsToken = 68, - BarEqualsToken = 69, - CaretEqualsToken = 70, - Identifier = 71, - BreakKeyword = 72, - CaseKeyword = 73, - CatchKeyword = 74, - ClassKeyword = 75, - ConstKeyword = 76, - ContinueKeyword = 77, - DebuggerKeyword = 78, - DefaultKeyword = 79, - DeleteKeyword = 80, - DoKeyword = 81, - ElseKeyword = 82, - EnumKeyword = 83, - ExportKeyword = 84, - ExtendsKeyword = 85, - FalseKeyword = 86, - FinallyKeyword = 87, - ForKeyword = 88, - FunctionKeyword = 89, - IfKeyword = 90, - ImportKeyword = 91, - InKeyword = 92, - InstanceOfKeyword = 93, - NewKeyword = 94, - NullKeyword = 95, - ReturnKeyword = 96, - SuperKeyword = 97, - SwitchKeyword = 98, - ThisKeyword = 99, - ThrowKeyword = 100, - TrueKeyword = 101, - TryKeyword = 102, - TypeOfKeyword = 103, - VarKeyword = 104, - VoidKeyword = 105, - WhileKeyword = 106, - WithKeyword = 107, - ImplementsKeyword = 108, - InterfaceKeyword = 109, - LetKeyword = 110, - PackageKeyword = 111, - PrivateKeyword = 112, - ProtectedKeyword = 113, - PublicKeyword = 114, - StaticKeyword = 115, - YieldKeyword = 116, - AbstractKeyword = 117, - AsKeyword = 118, - AnyKeyword = 119, - AsyncKeyword = 120, - AwaitKeyword = 121, - BooleanKeyword = 122, - ConstructorKeyword = 123, - DeclareKeyword = 124, - GetKeyword = 125, - InferKeyword = 126, - IsKeyword = 127, - KeyOfKeyword = 128, - ModuleKeyword = 129, - NamespaceKeyword = 130, - NeverKeyword = 131, - ReadonlyKeyword = 132, - RequireKeyword = 133, - NumberKeyword = 134, - ObjectKeyword = 135, - SetKeyword = 136, - StringKeyword = 137, - SymbolKeyword = 138, - TypeKeyword = 139, - UndefinedKeyword = 140, - UniqueKeyword = 141, - UnknownKeyword = 142, - FromKeyword = 143, - GlobalKeyword = 144, - BigIntKeyword = 145, - OfKeyword = 146, - QualifiedName = 147, - ComputedPropertyName = 148, - TypeParameter = 149, - Parameter = 150, - Decorator = 151, - PropertySignature = 152, - PropertyDeclaration = 153, - MethodSignature = 154, - MethodDeclaration = 155, - Constructor = 156, - GetAccessor = 157, - SetAccessor = 158, - CallSignature = 159, - ConstructSignature = 160, - IndexSignature = 161, - TypePredicate = 162, - TypeReference = 163, - FunctionType = 164, - ConstructorType = 165, - TypeQuery = 166, - TypeLiteral = 167, - ArrayType = 168, - TupleType = 169, - OptionalType = 170, - RestType = 171, - UnionType = 172, - IntersectionType = 173, - ConditionalType = 174, - InferType = 175, - ParenthesizedType = 176, - ThisType = 177, - TypeOperator = 178, - IndexedAccessType = 179, - MappedType = 180, - LiteralType = 181, - ImportType = 182, - ObjectBindingPattern = 183, - ArrayBindingPattern = 184, - BindingElement = 185, - ArrayLiteralExpression = 186, - ObjectLiteralExpression = 187, - PropertyAccessExpression = 188, - ElementAccessExpression = 189, - CallExpression = 190, - NewExpression = 191, - TaggedTemplateExpression = 192, - TypeAssertionExpression = 193, - ParenthesizedExpression = 194, - FunctionExpression = 195, - ArrowFunction = 196, - DeleteExpression = 197, - TypeOfExpression = 198, - VoidExpression = 199, - AwaitExpression = 200, - PrefixUnaryExpression = 201, - PostfixUnaryExpression = 202, - BinaryExpression = 203, - ConditionalExpression = 204, - TemplateExpression = 205, - YieldExpression = 206, - SpreadElement = 207, - ClassExpression = 208, - OmittedExpression = 209, - ExpressionWithTypeArguments = 210, - AsExpression = 211, - NonNullExpression = 212, - MetaProperty = 213, - SyntheticExpression = 214, - TemplateSpan = 215, - SemicolonClassElement = 216, - Block = 217, - VariableStatement = 218, - EmptyStatement = 219, - ExpressionStatement = 220, - IfStatement = 221, - DoStatement = 222, - WhileStatement = 223, - ForStatement = 224, - ForInStatement = 225, - ForOfStatement = 226, - ContinueStatement = 227, - BreakStatement = 228, - ReturnStatement = 229, - WithStatement = 230, - SwitchStatement = 231, - LabeledStatement = 232, - ThrowStatement = 233, - TryStatement = 234, - DebuggerStatement = 235, - VariableDeclaration = 236, - VariableDeclarationList = 237, - FunctionDeclaration = 238, - ClassDeclaration = 239, - InterfaceDeclaration = 240, - TypeAliasDeclaration = 241, - EnumDeclaration = 242, - ModuleDeclaration = 243, - ModuleBlock = 244, - CaseBlock = 245, - NamespaceExportDeclaration = 246, - ImportEqualsDeclaration = 247, - ImportDeclaration = 248, - ImportClause = 249, - NamespaceImport = 250, - NamedImports = 251, - ImportSpecifier = 252, - ExportAssignment = 253, - ExportDeclaration = 254, - NamedExports = 255, - ExportSpecifier = 256, - MissingDeclaration = 257, - ExternalModuleReference = 258, - JsxElement = 259, - JsxSelfClosingElement = 260, - JsxOpeningElement = 261, - JsxClosingElement = 262, - JsxFragment = 263, - JsxOpeningFragment = 264, - JsxClosingFragment = 265, - JsxAttribute = 266, - JsxAttributes = 267, - JsxSpreadAttribute = 268, - JsxExpression = 269, - CaseClause = 270, - DefaultClause = 271, - HeritageClause = 272, - CatchClause = 273, - PropertyAssignment = 274, - ShorthandPropertyAssignment = 275, - SpreadAssignment = 276, - EnumMember = 277, - SourceFile = 278, - Bundle = 279, - UnparsedSource = 280, - InputFiles = 281, - JSDocTypeExpression = 282, - JSDocAllType = 283, - JSDocUnknownType = 284, - JSDocNullableType = 285, - JSDocNonNullableType = 286, - JSDocOptionalType = 287, - JSDocFunctionType = 288, - JSDocVariadicType = 289, - JSDocComment = 290, - JSDocTypeLiteral = 291, - JSDocSignature = 292, - JSDocTag = 293, - JSDocAugmentsTag = 294, - JSDocClassTag = 295, - JSDocCallbackTag = 296, - JSDocEnumTag = 297, - JSDocParameterTag = 298, - JSDocReturnTag = 299, - JSDocThisTag = 300, - JSDocTypeTag = 301, - JSDocTemplateTag = 302, - JSDocTypedefTag = 303, - JSDocPropertyTag = 304, - SyntaxList = 305, - NotEmittedStatement = 306, - PartiallyEmittedExpression = 307, - CommaListExpression = 308, - MergeDeclarationMarker = 309, - EndOfDeclarationMarker = 310, - Count = 311, - FirstAssignment = 58, - LastAssignment = 70, - FirstCompoundAssignment = 59, - LastCompoundAssignment = 70, - FirstReservedWord = 72, - LastReservedWord = 107, - FirstKeyword = 72, - LastKeyword = 146, - FirstFutureReservedWord = 108, - LastFutureReservedWord = 116, - FirstTypeNode = 162, - LastTypeNode = 182, - FirstPunctuation = 17, - LastPunctuation = 70, + BigIntLiteral = 9, + StringLiteral = 10, + JsxText = 11, + JsxTextAllWhiteSpaces = 12, + RegularExpressionLiteral = 13, + NoSubstitutionTemplateLiteral = 14, + TemplateHead = 15, + TemplateMiddle = 16, + TemplateTail = 17, + OpenBraceToken = 18, + CloseBraceToken = 19, + OpenParenToken = 20, + CloseParenToken = 21, + OpenBracketToken = 22, + CloseBracketToken = 23, + DotToken = 24, + DotDotDotToken = 25, + SemicolonToken = 26, + CommaToken = 27, + LessThanToken = 28, + LessThanSlashToken = 29, + GreaterThanToken = 30, + LessThanEqualsToken = 31, + GreaterThanEqualsToken = 32, + EqualsEqualsToken = 33, + ExclamationEqualsToken = 34, + EqualsEqualsEqualsToken = 35, + ExclamationEqualsEqualsToken = 36, + EqualsGreaterThanToken = 37, + PlusToken = 38, + MinusToken = 39, + AsteriskToken = 40, + AsteriskAsteriskToken = 41, + SlashToken = 42, + PercentToken = 43, + PlusPlusToken = 44, + MinusMinusToken = 45, + LessThanLessThanToken = 46, + GreaterThanGreaterThanToken = 47, + GreaterThanGreaterThanGreaterThanToken = 48, + AmpersandToken = 49, + BarToken = 50, + CaretToken = 51, + ExclamationToken = 52, + TildeToken = 53, + AmpersandAmpersandToken = 54, + BarBarToken = 55, + QuestionToken = 56, + ColonToken = 57, + AtToken = 58, + EqualsToken = 59, + PlusEqualsToken = 60, + MinusEqualsToken = 61, + AsteriskEqualsToken = 62, + AsteriskAsteriskEqualsToken = 63, + SlashEqualsToken = 64, + PercentEqualsToken = 65, + LessThanLessThanEqualsToken = 66, + GreaterThanGreaterThanEqualsToken = 67, + GreaterThanGreaterThanGreaterThanEqualsToken = 68, + AmpersandEqualsToken = 69, + BarEqualsToken = 70, + CaretEqualsToken = 71, + Identifier = 72, + BreakKeyword = 73, + CaseKeyword = 74, + CatchKeyword = 75, + ClassKeyword = 76, + ConstKeyword = 77, + ContinueKeyword = 78, + DebuggerKeyword = 79, + DefaultKeyword = 80, + DeleteKeyword = 81, + DoKeyword = 82, + ElseKeyword = 83, + EnumKeyword = 84, + ExportKeyword = 85, + ExtendsKeyword = 86, + FalseKeyword = 87, + FinallyKeyword = 88, + ForKeyword = 89, + FunctionKeyword = 90, + IfKeyword = 91, + ImportKeyword = 92, + InKeyword = 93, + InstanceOfKeyword = 94, + NewKeyword = 95, + NullKeyword = 96, + ReturnKeyword = 97, + SuperKeyword = 98, + SwitchKeyword = 99, + ThisKeyword = 100, + ThrowKeyword = 101, + TrueKeyword = 102, + TryKeyword = 103, + TypeOfKeyword = 104, + VarKeyword = 105, + VoidKeyword = 106, + WhileKeyword = 107, + WithKeyword = 108, + ImplementsKeyword = 109, + InterfaceKeyword = 110, + LetKeyword = 111, + PackageKeyword = 112, + PrivateKeyword = 113, + ProtectedKeyword = 114, + PublicKeyword = 115, + StaticKeyword = 116, + YieldKeyword = 117, + AbstractKeyword = 118, + AsKeyword = 119, + AnyKeyword = 120, + AsyncKeyword = 121, + AwaitKeyword = 122, + BooleanKeyword = 123, + ConstructorKeyword = 124, + DeclareKeyword = 125, + GetKeyword = 126, + InferKeyword = 127, + IsKeyword = 128, + KeyOfKeyword = 129, + ModuleKeyword = 130, + NamespaceKeyword = 131, + NeverKeyword = 132, + ReadonlyKeyword = 133, + RequireKeyword = 134, + NumberKeyword = 135, + ObjectKeyword = 136, + SetKeyword = 137, + StringKeyword = 138, + SymbolKeyword = 139, + TypeKeyword = 140, + UndefinedKeyword = 141, + UniqueKeyword = 142, + UnknownKeyword = 143, + FromKeyword = 144, + GlobalKeyword = 145, + BigIntKeyword = 146, + OfKeyword = 147, + QualifiedName = 148, + ComputedPropertyName = 149, + TypeParameter = 150, + Parameter = 151, + Decorator = 152, + PropertySignature = 153, + PropertyDeclaration = 154, + MethodSignature = 155, + MethodDeclaration = 156, + Constructor = 157, + GetAccessor = 158, + SetAccessor = 159, + CallSignature = 160, + ConstructSignature = 161, + IndexSignature = 162, + TypePredicate = 163, + TypeReference = 164, + FunctionType = 165, + ConstructorType = 166, + TypeQuery = 167, + TypeLiteral = 168, + ArrayType = 169, + TupleType = 170, + OptionalType = 171, + RestType = 172, + UnionType = 173, + IntersectionType = 174, + ConditionalType = 175, + InferType = 176, + ParenthesizedType = 177, + ThisType = 178, + TypeOperator = 179, + IndexedAccessType = 180, + MappedType = 181, + LiteralType = 182, + ImportType = 183, + ObjectBindingPattern = 184, + ArrayBindingPattern = 185, + BindingElement = 186, + ArrayLiteralExpression = 187, + ObjectLiteralExpression = 188, + PropertyAccessExpression = 189, + ElementAccessExpression = 190, + CallExpression = 191, + NewExpression = 192, + TaggedTemplateExpression = 193, + TypeAssertionExpression = 194, + ParenthesizedExpression = 195, + FunctionExpression = 196, + ArrowFunction = 197, + DeleteExpression = 198, + TypeOfExpression = 199, + VoidExpression = 200, + AwaitExpression = 201, + PrefixUnaryExpression = 202, + PostfixUnaryExpression = 203, + BinaryExpression = 204, + ConditionalExpression = 205, + TemplateExpression = 206, + YieldExpression = 207, + SpreadElement = 208, + ClassExpression = 209, + OmittedExpression = 210, + ExpressionWithTypeArguments = 211, + AsExpression = 212, + NonNullExpression = 213, + MetaProperty = 214, + SyntheticExpression = 215, + TemplateSpan = 216, + SemicolonClassElement = 217, + Block = 218, + VariableStatement = 219, + EmptyStatement = 220, + ExpressionStatement = 221, + IfStatement = 222, + DoStatement = 223, + WhileStatement = 224, + ForStatement = 225, + ForInStatement = 226, + ForOfStatement = 227, + ContinueStatement = 228, + BreakStatement = 229, + ReturnStatement = 230, + WithStatement = 231, + SwitchStatement = 232, + LabeledStatement = 233, + ThrowStatement = 234, + TryStatement = 235, + DebuggerStatement = 236, + VariableDeclaration = 237, + VariableDeclarationList = 238, + FunctionDeclaration = 239, + ClassDeclaration = 240, + InterfaceDeclaration = 241, + TypeAliasDeclaration = 242, + EnumDeclaration = 243, + ModuleDeclaration = 244, + ModuleBlock = 245, + CaseBlock = 246, + NamespaceExportDeclaration = 247, + ImportEqualsDeclaration = 248, + ImportDeclaration = 249, + ImportClause = 250, + NamespaceImport = 251, + NamedImports = 252, + ImportSpecifier = 253, + ExportAssignment = 254, + ExportDeclaration = 255, + NamedExports = 256, + ExportSpecifier = 257, + MissingDeclaration = 258, + ExternalModuleReference = 259, + JsxElement = 260, + JsxSelfClosingElement = 261, + JsxOpeningElement = 262, + JsxClosingElement = 263, + JsxFragment = 264, + JsxOpeningFragment = 265, + JsxClosingFragment = 266, + JsxAttribute = 267, + JsxAttributes = 268, + JsxSpreadAttribute = 269, + JsxExpression = 270, + CaseClause = 271, + DefaultClause = 272, + HeritageClause = 273, + CatchClause = 274, + PropertyAssignment = 275, + ShorthandPropertyAssignment = 276, + SpreadAssignment = 277, + EnumMember = 278, + SourceFile = 279, + Bundle = 280, + UnparsedSource = 281, + InputFiles = 282, + JSDocTypeExpression = 283, + JSDocAllType = 284, + JSDocUnknownType = 285, + JSDocNullableType = 286, + JSDocNonNullableType = 287, + JSDocOptionalType = 288, + JSDocFunctionType = 289, + JSDocVariadicType = 290, + JSDocComment = 291, + JSDocTypeLiteral = 292, + JSDocSignature = 293, + JSDocTag = 294, + JSDocAugmentsTag = 295, + JSDocClassTag = 296, + JSDocCallbackTag = 297, + JSDocEnumTag = 298, + JSDocParameterTag = 299, + JSDocReturnTag = 300, + JSDocThisTag = 301, + JSDocTypeTag = 302, + JSDocTemplateTag = 303, + JSDocTypedefTag = 304, + JSDocPropertyTag = 305, + SyntaxList = 306, + NotEmittedStatement = 307, + PartiallyEmittedExpression = 308, + CommaListExpression = 309, + MergeDeclarationMarker = 310, + EndOfDeclarationMarker = 311, + Count = 312, + FirstAssignment = 59, + LastAssignment = 71, + FirstCompoundAssignment = 60, + LastCompoundAssignment = 71, + FirstReservedWord = 73, + LastReservedWord = 108, + FirstKeyword = 73, + LastKeyword = 147, + FirstFutureReservedWord = 109, + LastFutureReservedWord = 117, + FirstTypeNode = 163, + LastTypeNode = 183, + FirstPunctuation = 18, + LastPunctuation = 71, FirstToken = 0, - LastToken = 146, + LastToken = 147, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, - LastLiteralToken = 13, - FirstTemplateToken = 13, - LastTemplateToken = 16, - FirstBinaryOperator = 27, - LastBinaryOperator = 70, - FirstNode = 147, - FirstJSDocNode = 282, - LastJSDocNode = 304, - FirstJSDocTagNode = 293, - LastJSDocTagNode = 304 + LastLiteralToken = 14, + FirstTemplateToken = 14, + LastTemplateToken = 17, + FirstBinaryOperator = 28, + LastBinaryOperator = 71, + FirstNode = 148, + FirstJSDocNode = 283, + LastJSDocNode = 305, + FirstJSDocTagNode = 294, + LastJSDocTagNode = 305 } enum NodeFlags { None = 0, @@ -1000,6 +1001,9 @@ declare namespace ts { interface NumericLiteral extends LiteralExpression { kind: SyntaxKind.NumericLiteral; } + interface BigIntLiteral extends LiteralExpression { + kind: SyntaxKind.BigIntLiteral; + } interface TemplateHead extends LiteralLikeNode { kind: SyntaxKind.TemplateHead; parent: TemplateExpression; @@ -3308,6 +3312,7 @@ declare namespace ts { } declare namespace ts { function isNumericLiteral(node: Node): node is NumericLiteral; + function isBigIntLiteral(node: Node): node is BigIntLiteral; function isStringLiteral(node: Node): node is StringLiteral; function isJsxText(node: Node): node is JsxText; function isRegularExpressionLiteral(node: Node): node is RegularExpressionLiteral; @@ -3669,6 +3674,7 @@ declare namespace ts { function createLiteral(value: boolean): BooleanLiteral; function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression; function createNumericLiteral(value: string): NumericLiteral; + function createBigIntLiteral(value: string): BigIntLiteral; function createStringLiteral(text: string): StringLiteral; function createRegularExpressionLiteral(text: string): RegularExpressionLiteral; function createIdentifier(text: string): Identifier; @@ -5269,8 +5275,9 @@ declare namespace ts { Whitespace = 4, Identifier = 5, NumberLiteral = 6, - StringLiteral = 7, - RegExpLiteral = 8 + BigIntLiteral = 7, + StringLiteral = 8, + RegExpLiteral = 9 } interface ClassificationResult { finalLexState: EndOfLineState; @@ -5395,6 +5402,7 @@ declare namespace ts { identifier = "identifier", keyword = "keyword", numericLiteral = "number", + bigintLiteral = "bigint", operator = "operator", stringLiteral = "string", whiteSpace = "whitespace", @@ -5439,7 +5447,8 @@ declare namespace ts { jsxSelfClosingTagName = 21, jsxAttribute = 22, jsxText = 23, - jsxAttributeStringLiteralValue = 24 + jsxAttributeStringLiteralValue = 24, + bigintLiteral = 25 } } declare namespace ts { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fee1057fd2d..ec80d7722e2 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -85,338 +85,339 @@ declare namespace ts { ShebangTrivia = 6, ConflictMarkerTrivia = 7, NumericLiteral = 8, - StringLiteral = 9, - JsxText = 10, - JsxTextAllWhiteSpaces = 11, - RegularExpressionLiteral = 12, - NoSubstitutionTemplateLiteral = 13, - TemplateHead = 14, - TemplateMiddle = 15, - TemplateTail = 16, - OpenBraceToken = 17, - CloseBraceToken = 18, - OpenParenToken = 19, - CloseParenToken = 20, - OpenBracketToken = 21, - CloseBracketToken = 22, - DotToken = 23, - DotDotDotToken = 24, - SemicolonToken = 25, - CommaToken = 26, - LessThanToken = 27, - LessThanSlashToken = 28, - GreaterThanToken = 29, - LessThanEqualsToken = 30, - GreaterThanEqualsToken = 31, - EqualsEqualsToken = 32, - ExclamationEqualsToken = 33, - EqualsEqualsEqualsToken = 34, - ExclamationEqualsEqualsToken = 35, - EqualsGreaterThanToken = 36, - PlusToken = 37, - MinusToken = 38, - AsteriskToken = 39, - AsteriskAsteriskToken = 40, - SlashToken = 41, - PercentToken = 42, - PlusPlusToken = 43, - MinusMinusToken = 44, - LessThanLessThanToken = 45, - GreaterThanGreaterThanToken = 46, - GreaterThanGreaterThanGreaterThanToken = 47, - AmpersandToken = 48, - BarToken = 49, - CaretToken = 50, - ExclamationToken = 51, - TildeToken = 52, - AmpersandAmpersandToken = 53, - BarBarToken = 54, - QuestionToken = 55, - ColonToken = 56, - AtToken = 57, - EqualsToken = 58, - PlusEqualsToken = 59, - MinusEqualsToken = 60, - AsteriskEqualsToken = 61, - AsteriskAsteriskEqualsToken = 62, - SlashEqualsToken = 63, - PercentEqualsToken = 64, - LessThanLessThanEqualsToken = 65, - GreaterThanGreaterThanEqualsToken = 66, - GreaterThanGreaterThanGreaterThanEqualsToken = 67, - AmpersandEqualsToken = 68, - BarEqualsToken = 69, - CaretEqualsToken = 70, - Identifier = 71, - BreakKeyword = 72, - CaseKeyword = 73, - CatchKeyword = 74, - ClassKeyword = 75, - ConstKeyword = 76, - ContinueKeyword = 77, - DebuggerKeyword = 78, - DefaultKeyword = 79, - DeleteKeyword = 80, - DoKeyword = 81, - ElseKeyword = 82, - EnumKeyword = 83, - ExportKeyword = 84, - ExtendsKeyword = 85, - FalseKeyword = 86, - FinallyKeyword = 87, - ForKeyword = 88, - FunctionKeyword = 89, - IfKeyword = 90, - ImportKeyword = 91, - InKeyword = 92, - InstanceOfKeyword = 93, - NewKeyword = 94, - NullKeyword = 95, - ReturnKeyword = 96, - SuperKeyword = 97, - SwitchKeyword = 98, - ThisKeyword = 99, - ThrowKeyword = 100, - TrueKeyword = 101, - TryKeyword = 102, - TypeOfKeyword = 103, - VarKeyword = 104, - VoidKeyword = 105, - WhileKeyword = 106, - WithKeyword = 107, - ImplementsKeyword = 108, - InterfaceKeyword = 109, - LetKeyword = 110, - PackageKeyword = 111, - PrivateKeyword = 112, - ProtectedKeyword = 113, - PublicKeyword = 114, - StaticKeyword = 115, - YieldKeyword = 116, - AbstractKeyword = 117, - AsKeyword = 118, - AnyKeyword = 119, - AsyncKeyword = 120, - AwaitKeyword = 121, - BooleanKeyword = 122, - ConstructorKeyword = 123, - DeclareKeyword = 124, - GetKeyword = 125, - InferKeyword = 126, - IsKeyword = 127, - KeyOfKeyword = 128, - ModuleKeyword = 129, - NamespaceKeyword = 130, - NeverKeyword = 131, - ReadonlyKeyword = 132, - RequireKeyword = 133, - NumberKeyword = 134, - ObjectKeyword = 135, - SetKeyword = 136, - StringKeyword = 137, - SymbolKeyword = 138, - TypeKeyword = 139, - UndefinedKeyword = 140, - UniqueKeyword = 141, - UnknownKeyword = 142, - FromKeyword = 143, - GlobalKeyword = 144, - BigIntKeyword = 145, - OfKeyword = 146, - QualifiedName = 147, - ComputedPropertyName = 148, - TypeParameter = 149, - Parameter = 150, - Decorator = 151, - PropertySignature = 152, - PropertyDeclaration = 153, - MethodSignature = 154, - MethodDeclaration = 155, - Constructor = 156, - GetAccessor = 157, - SetAccessor = 158, - CallSignature = 159, - ConstructSignature = 160, - IndexSignature = 161, - TypePredicate = 162, - TypeReference = 163, - FunctionType = 164, - ConstructorType = 165, - TypeQuery = 166, - TypeLiteral = 167, - ArrayType = 168, - TupleType = 169, - OptionalType = 170, - RestType = 171, - UnionType = 172, - IntersectionType = 173, - ConditionalType = 174, - InferType = 175, - ParenthesizedType = 176, - ThisType = 177, - TypeOperator = 178, - IndexedAccessType = 179, - MappedType = 180, - LiteralType = 181, - ImportType = 182, - ObjectBindingPattern = 183, - ArrayBindingPattern = 184, - BindingElement = 185, - ArrayLiteralExpression = 186, - ObjectLiteralExpression = 187, - PropertyAccessExpression = 188, - ElementAccessExpression = 189, - CallExpression = 190, - NewExpression = 191, - TaggedTemplateExpression = 192, - TypeAssertionExpression = 193, - ParenthesizedExpression = 194, - FunctionExpression = 195, - ArrowFunction = 196, - DeleteExpression = 197, - TypeOfExpression = 198, - VoidExpression = 199, - AwaitExpression = 200, - PrefixUnaryExpression = 201, - PostfixUnaryExpression = 202, - BinaryExpression = 203, - ConditionalExpression = 204, - TemplateExpression = 205, - YieldExpression = 206, - SpreadElement = 207, - ClassExpression = 208, - OmittedExpression = 209, - ExpressionWithTypeArguments = 210, - AsExpression = 211, - NonNullExpression = 212, - MetaProperty = 213, - SyntheticExpression = 214, - TemplateSpan = 215, - SemicolonClassElement = 216, - Block = 217, - VariableStatement = 218, - EmptyStatement = 219, - ExpressionStatement = 220, - IfStatement = 221, - DoStatement = 222, - WhileStatement = 223, - ForStatement = 224, - ForInStatement = 225, - ForOfStatement = 226, - ContinueStatement = 227, - BreakStatement = 228, - ReturnStatement = 229, - WithStatement = 230, - SwitchStatement = 231, - LabeledStatement = 232, - ThrowStatement = 233, - TryStatement = 234, - DebuggerStatement = 235, - VariableDeclaration = 236, - VariableDeclarationList = 237, - FunctionDeclaration = 238, - ClassDeclaration = 239, - InterfaceDeclaration = 240, - TypeAliasDeclaration = 241, - EnumDeclaration = 242, - ModuleDeclaration = 243, - ModuleBlock = 244, - CaseBlock = 245, - NamespaceExportDeclaration = 246, - ImportEqualsDeclaration = 247, - ImportDeclaration = 248, - ImportClause = 249, - NamespaceImport = 250, - NamedImports = 251, - ImportSpecifier = 252, - ExportAssignment = 253, - ExportDeclaration = 254, - NamedExports = 255, - ExportSpecifier = 256, - MissingDeclaration = 257, - ExternalModuleReference = 258, - JsxElement = 259, - JsxSelfClosingElement = 260, - JsxOpeningElement = 261, - JsxClosingElement = 262, - JsxFragment = 263, - JsxOpeningFragment = 264, - JsxClosingFragment = 265, - JsxAttribute = 266, - JsxAttributes = 267, - JsxSpreadAttribute = 268, - JsxExpression = 269, - CaseClause = 270, - DefaultClause = 271, - HeritageClause = 272, - CatchClause = 273, - PropertyAssignment = 274, - ShorthandPropertyAssignment = 275, - SpreadAssignment = 276, - EnumMember = 277, - SourceFile = 278, - Bundle = 279, - UnparsedSource = 280, - InputFiles = 281, - JSDocTypeExpression = 282, - JSDocAllType = 283, - JSDocUnknownType = 284, - JSDocNullableType = 285, - JSDocNonNullableType = 286, - JSDocOptionalType = 287, - JSDocFunctionType = 288, - JSDocVariadicType = 289, - JSDocComment = 290, - JSDocTypeLiteral = 291, - JSDocSignature = 292, - JSDocTag = 293, - JSDocAugmentsTag = 294, - JSDocClassTag = 295, - JSDocCallbackTag = 296, - JSDocEnumTag = 297, - JSDocParameterTag = 298, - JSDocReturnTag = 299, - JSDocThisTag = 300, - JSDocTypeTag = 301, - JSDocTemplateTag = 302, - JSDocTypedefTag = 303, - JSDocPropertyTag = 304, - SyntaxList = 305, - NotEmittedStatement = 306, - PartiallyEmittedExpression = 307, - CommaListExpression = 308, - MergeDeclarationMarker = 309, - EndOfDeclarationMarker = 310, - Count = 311, - FirstAssignment = 58, - LastAssignment = 70, - FirstCompoundAssignment = 59, - LastCompoundAssignment = 70, - FirstReservedWord = 72, - LastReservedWord = 107, - FirstKeyword = 72, - LastKeyword = 146, - FirstFutureReservedWord = 108, - LastFutureReservedWord = 116, - FirstTypeNode = 162, - LastTypeNode = 182, - FirstPunctuation = 17, - LastPunctuation = 70, + BigIntLiteral = 9, + StringLiteral = 10, + JsxText = 11, + JsxTextAllWhiteSpaces = 12, + RegularExpressionLiteral = 13, + NoSubstitutionTemplateLiteral = 14, + TemplateHead = 15, + TemplateMiddle = 16, + TemplateTail = 17, + OpenBraceToken = 18, + CloseBraceToken = 19, + OpenParenToken = 20, + CloseParenToken = 21, + OpenBracketToken = 22, + CloseBracketToken = 23, + DotToken = 24, + DotDotDotToken = 25, + SemicolonToken = 26, + CommaToken = 27, + LessThanToken = 28, + LessThanSlashToken = 29, + GreaterThanToken = 30, + LessThanEqualsToken = 31, + GreaterThanEqualsToken = 32, + EqualsEqualsToken = 33, + ExclamationEqualsToken = 34, + EqualsEqualsEqualsToken = 35, + ExclamationEqualsEqualsToken = 36, + EqualsGreaterThanToken = 37, + PlusToken = 38, + MinusToken = 39, + AsteriskToken = 40, + AsteriskAsteriskToken = 41, + SlashToken = 42, + PercentToken = 43, + PlusPlusToken = 44, + MinusMinusToken = 45, + LessThanLessThanToken = 46, + GreaterThanGreaterThanToken = 47, + GreaterThanGreaterThanGreaterThanToken = 48, + AmpersandToken = 49, + BarToken = 50, + CaretToken = 51, + ExclamationToken = 52, + TildeToken = 53, + AmpersandAmpersandToken = 54, + BarBarToken = 55, + QuestionToken = 56, + ColonToken = 57, + AtToken = 58, + EqualsToken = 59, + PlusEqualsToken = 60, + MinusEqualsToken = 61, + AsteriskEqualsToken = 62, + AsteriskAsteriskEqualsToken = 63, + SlashEqualsToken = 64, + PercentEqualsToken = 65, + LessThanLessThanEqualsToken = 66, + GreaterThanGreaterThanEqualsToken = 67, + GreaterThanGreaterThanGreaterThanEqualsToken = 68, + AmpersandEqualsToken = 69, + BarEqualsToken = 70, + CaretEqualsToken = 71, + Identifier = 72, + BreakKeyword = 73, + CaseKeyword = 74, + CatchKeyword = 75, + ClassKeyword = 76, + ConstKeyword = 77, + ContinueKeyword = 78, + DebuggerKeyword = 79, + DefaultKeyword = 80, + DeleteKeyword = 81, + DoKeyword = 82, + ElseKeyword = 83, + EnumKeyword = 84, + ExportKeyword = 85, + ExtendsKeyword = 86, + FalseKeyword = 87, + FinallyKeyword = 88, + ForKeyword = 89, + FunctionKeyword = 90, + IfKeyword = 91, + ImportKeyword = 92, + InKeyword = 93, + InstanceOfKeyword = 94, + NewKeyword = 95, + NullKeyword = 96, + ReturnKeyword = 97, + SuperKeyword = 98, + SwitchKeyword = 99, + ThisKeyword = 100, + ThrowKeyword = 101, + TrueKeyword = 102, + TryKeyword = 103, + TypeOfKeyword = 104, + VarKeyword = 105, + VoidKeyword = 106, + WhileKeyword = 107, + WithKeyword = 108, + ImplementsKeyword = 109, + InterfaceKeyword = 110, + LetKeyword = 111, + PackageKeyword = 112, + PrivateKeyword = 113, + ProtectedKeyword = 114, + PublicKeyword = 115, + StaticKeyword = 116, + YieldKeyword = 117, + AbstractKeyword = 118, + AsKeyword = 119, + AnyKeyword = 120, + AsyncKeyword = 121, + AwaitKeyword = 122, + BooleanKeyword = 123, + ConstructorKeyword = 124, + DeclareKeyword = 125, + GetKeyword = 126, + InferKeyword = 127, + IsKeyword = 128, + KeyOfKeyword = 129, + ModuleKeyword = 130, + NamespaceKeyword = 131, + NeverKeyword = 132, + ReadonlyKeyword = 133, + RequireKeyword = 134, + NumberKeyword = 135, + ObjectKeyword = 136, + SetKeyword = 137, + StringKeyword = 138, + SymbolKeyword = 139, + TypeKeyword = 140, + UndefinedKeyword = 141, + UniqueKeyword = 142, + UnknownKeyword = 143, + FromKeyword = 144, + GlobalKeyword = 145, + BigIntKeyword = 146, + OfKeyword = 147, + QualifiedName = 148, + ComputedPropertyName = 149, + TypeParameter = 150, + Parameter = 151, + Decorator = 152, + PropertySignature = 153, + PropertyDeclaration = 154, + MethodSignature = 155, + MethodDeclaration = 156, + Constructor = 157, + GetAccessor = 158, + SetAccessor = 159, + CallSignature = 160, + ConstructSignature = 161, + IndexSignature = 162, + TypePredicate = 163, + TypeReference = 164, + FunctionType = 165, + ConstructorType = 166, + TypeQuery = 167, + TypeLiteral = 168, + ArrayType = 169, + TupleType = 170, + OptionalType = 171, + RestType = 172, + UnionType = 173, + IntersectionType = 174, + ConditionalType = 175, + InferType = 176, + ParenthesizedType = 177, + ThisType = 178, + TypeOperator = 179, + IndexedAccessType = 180, + MappedType = 181, + LiteralType = 182, + ImportType = 183, + ObjectBindingPattern = 184, + ArrayBindingPattern = 185, + BindingElement = 186, + ArrayLiteralExpression = 187, + ObjectLiteralExpression = 188, + PropertyAccessExpression = 189, + ElementAccessExpression = 190, + CallExpression = 191, + NewExpression = 192, + TaggedTemplateExpression = 193, + TypeAssertionExpression = 194, + ParenthesizedExpression = 195, + FunctionExpression = 196, + ArrowFunction = 197, + DeleteExpression = 198, + TypeOfExpression = 199, + VoidExpression = 200, + AwaitExpression = 201, + PrefixUnaryExpression = 202, + PostfixUnaryExpression = 203, + BinaryExpression = 204, + ConditionalExpression = 205, + TemplateExpression = 206, + YieldExpression = 207, + SpreadElement = 208, + ClassExpression = 209, + OmittedExpression = 210, + ExpressionWithTypeArguments = 211, + AsExpression = 212, + NonNullExpression = 213, + MetaProperty = 214, + SyntheticExpression = 215, + TemplateSpan = 216, + SemicolonClassElement = 217, + Block = 218, + VariableStatement = 219, + EmptyStatement = 220, + ExpressionStatement = 221, + IfStatement = 222, + DoStatement = 223, + WhileStatement = 224, + ForStatement = 225, + ForInStatement = 226, + ForOfStatement = 227, + ContinueStatement = 228, + BreakStatement = 229, + ReturnStatement = 230, + WithStatement = 231, + SwitchStatement = 232, + LabeledStatement = 233, + ThrowStatement = 234, + TryStatement = 235, + DebuggerStatement = 236, + VariableDeclaration = 237, + VariableDeclarationList = 238, + FunctionDeclaration = 239, + ClassDeclaration = 240, + InterfaceDeclaration = 241, + TypeAliasDeclaration = 242, + EnumDeclaration = 243, + ModuleDeclaration = 244, + ModuleBlock = 245, + CaseBlock = 246, + NamespaceExportDeclaration = 247, + ImportEqualsDeclaration = 248, + ImportDeclaration = 249, + ImportClause = 250, + NamespaceImport = 251, + NamedImports = 252, + ImportSpecifier = 253, + ExportAssignment = 254, + ExportDeclaration = 255, + NamedExports = 256, + ExportSpecifier = 257, + MissingDeclaration = 258, + ExternalModuleReference = 259, + JsxElement = 260, + JsxSelfClosingElement = 261, + JsxOpeningElement = 262, + JsxClosingElement = 263, + JsxFragment = 264, + JsxOpeningFragment = 265, + JsxClosingFragment = 266, + JsxAttribute = 267, + JsxAttributes = 268, + JsxSpreadAttribute = 269, + JsxExpression = 270, + CaseClause = 271, + DefaultClause = 272, + HeritageClause = 273, + CatchClause = 274, + PropertyAssignment = 275, + ShorthandPropertyAssignment = 276, + SpreadAssignment = 277, + EnumMember = 278, + SourceFile = 279, + Bundle = 280, + UnparsedSource = 281, + InputFiles = 282, + JSDocTypeExpression = 283, + JSDocAllType = 284, + JSDocUnknownType = 285, + JSDocNullableType = 286, + JSDocNonNullableType = 287, + JSDocOptionalType = 288, + JSDocFunctionType = 289, + JSDocVariadicType = 290, + JSDocComment = 291, + JSDocTypeLiteral = 292, + JSDocSignature = 293, + JSDocTag = 294, + JSDocAugmentsTag = 295, + JSDocClassTag = 296, + JSDocCallbackTag = 297, + JSDocEnumTag = 298, + JSDocParameterTag = 299, + JSDocReturnTag = 300, + JSDocThisTag = 301, + JSDocTypeTag = 302, + JSDocTemplateTag = 303, + JSDocTypedefTag = 304, + JSDocPropertyTag = 305, + SyntaxList = 306, + NotEmittedStatement = 307, + PartiallyEmittedExpression = 308, + CommaListExpression = 309, + MergeDeclarationMarker = 310, + EndOfDeclarationMarker = 311, + Count = 312, + FirstAssignment = 59, + LastAssignment = 71, + FirstCompoundAssignment = 60, + LastCompoundAssignment = 71, + FirstReservedWord = 73, + LastReservedWord = 108, + FirstKeyword = 73, + LastKeyword = 147, + FirstFutureReservedWord = 109, + LastFutureReservedWord = 117, + FirstTypeNode = 163, + LastTypeNode = 183, + FirstPunctuation = 18, + LastPunctuation = 71, FirstToken = 0, - LastToken = 146, + LastToken = 147, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, - LastLiteralToken = 13, - FirstTemplateToken = 13, - LastTemplateToken = 16, - FirstBinaryOperator = 27, - LastBinaryOperator = 70, - FirstNode = 147, - FirstJSDocNode = 282, - LastJSDocNode = 304, - FirstJSDocTagNode = 293, - LastJSDocTagNode = 304 + LastLiteralToken = 14, + FirstTemplateToken = 14, + LastTemplateToken = 17, + FirstBinaryOperator = 28, + LastBinaryOperator = 71, + FirstNode = 148, + FirstJSDocNode = 283, + LastJSDocNode = 305, + FirstJSDocTagNode = 294, + LastJSDocTagNode = 305 } enum NodeFlags { None = 0, @@ -1000,6 +1001,9 @@ declare namespace ts { interface NumericLiteral extends LiteralExpression { kind: SyntaxKind.NumericLiteral; } + interface BigIntLiteral extends LiteralExpression { + kind: SyntaxKind.BigIntLiteral; + } interface TemplateHead extends LiteralLikeNode { kind: SyntaxKind.TemplateHead; parent: TemplateExpression; @@ -3308,6 +3312,7 @@ declare namespace ts { } declare namespace ts { function isNumericLiteral(node: Node): node is NumericLiteral; + function isBigIntLiteral(node: Node): node is BigIntLiteral; function isStringLiteral(node: Node): node is StringLiteral; function isJsxText(node: Node): node is JsxText; function isRegularExpressionLiteral(node: Node): node is RegularExpressionLiteral; @@ -3669,6 +3674,7 @@ declare namespace ts { function createLiteral(value: boolean): BooleanLiteral; function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression; function createNumericLiteral(value: string): NumericLiteral; + function createBigIntLiteral(value: string): BigIntLiteral; function createStringLiteral(text: string): StringLiteral; function createRegularExpressionLiteral(text: string): RegularExpressionLiteral; function createIdentifier(text: string): Identifier; @@ -5269,8 +5275,9 @@ declare namespace ts { Whitespace = 4, Identifier = 5, NumberLiteral = 6, - StringLiteral = 7, - RegExpLiteral = 8 + BigIntLiteral = 7, + StringLiteral = 8, + RegExpLiteral = 9 } interface ClassificationResult { finalLexState: EndOfLineState; @@ -5395,6 +5402,7 @@ declare namespace ts { identifier = "identifier", keyword = "keyword", numericLiteral = "number", + bigintLiteral = "bigint", operator = "operator", stringLiteral = "string", whiteSpace = "whitespace", @@ -5439,7 +5447,8 @@ declare namespace ts { jsxSelfClosingTagName = 21, jsxAttribute = 22, jsxText = 23, - jsxAttributeStringLiteralValue = 24 + jsxAttributeStringLiteralValue = 24, + bigintLiteral = 25 } } declare namespace ts { diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index 94187845fc3..cddcd961338 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -34,7 +34,7 @@ key = "abc"; key = Symbol(); >key : Symbol(key, Decl(bigintIndex.ts, 9, 3)) ->Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) key = 123n; // should error >key : Symbol(key, Decl(bigintIndex.ts, 9, 3)) @@ -45,7 +45,7 @@ const bigNum: bigint = 0n; const typedArray = new Uint8Array(3); >typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --)) typedArray[bigNum] = 0xAA; // should error >typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5)) @@ -53,7 +53,7 @@ typedArray[bigNum] = 0xAA; // should error typedArray[String(bigNum)] = 0xAA; >typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5)) ->String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 1 more) +>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 2 more) >bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5)) typedArray["1"] = 0xBB; diff --git a/tests/baselines/reference/bigintWithLib.js b/tests/baselines/reference/bigintWithLib.js index e25decf9312..979e0d2b129 100644 --- a/tests/baselines/reference/bigintWithLib.js +++ b/tests/baselines/reference/bigintWithLib.js @@ -52,8 +52,8 @@ bigintVal = dataView.getBigUint64(2, true); let bigintVal = BigInt(123); bigintVal = BigInt("456"); new BigInt(123); // should error -bigintVal = BigInt.asIntN(8, 0xFFFFn); -bigintVal = BigInt.asUintN(8, 0xFFFFn); +bigintVal = BigInt.asIntN(8, 0xffffn); +bigintVal = BigInt.asUintN(8, 0xffffn); bigintVal = bigintVal.valueOf(); let stringVal = bigintVal.toString(); stringVal = bigintVal.toString(2); diff --git a/tests/baselines/reference/bigintWithoutLib.errors.txt b/tests/baselines/reference/bigintWithoutLib.errors.txt index d06e99464cd..90a0fdcc31b 100644 --- a/tests/baselines/reference/bigintWithoutLib.errors.txt +++ b/tests/baselines/reference/bigintWithoutLib.errors.txt @@ -2,13 +2,18 @@ tests/cases/compiler/bigintWithoutLib.ts(4,25): error TS2304: Cannot find name ' tests/cases/compiler/bigintWithoutLib.ts(5,13): error TS2304: Cannot find name 'BigInt'. tests/cases/compiler/bigintWithoutLib.ts(6,5): error TS2304: Cannot find name 'BigInt'. tests/cases/compiler/bigintWithoutLib.ts(7,13): error TS2304: Cannot find name 'BigInt'. +tests/cases/compiler/bigintWithoutLib.ts(7,30): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(8,13): error TS2304: Cannot find name 'BigInt'. +tests/cases/compiler/bigintWithoutLib.ts(8,31): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(9,1): error TS2322: Type 'Object' is not assignable to type 'bigint'. tests/cases/compiler/bigintWithoutLib.ts(11,13): error TS2554: Expected 0 arguments, but got 1. tests/cases/compiler/bigintWithoutLib.ts(15,18): error TS2304: Cannot find name 'BigInt64Array'. tests/cases/compiler/bigintWithoutLib.ts(15,38): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(16,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(17,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? +tests/cases/compiler/bigintWithoutLib.ts(17,34): error TS2736: BigInt literals are not available when targetting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(17,38): error TS2736: BigInt literals are not available when targetting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(17,42): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(18,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(19,19): error TS2304: Cannot find name 'BigInt64Array'. tests/cases/compiler/bigintWithoutLib.ts(20,19): error TS2304: Cannot find name 'BigInt64Array'. @@ -17,15 +22,22 @@ tests/cases/compiler/bigintWithoutLib.ts(27,19): error TS2304: Cannot find name tests/cases/compiler/bigintWithoutLib.ts(27,40): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(28,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(29,20): error TS2304: Cannot find name 'BigUint64Array'. +tests/cases/compiler/bigintWithoutLib.ts(29,36): error TS2736: BigInt literals are not available when targetting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(29,40): error TS2736: BigInt literals are not available when targetting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(29,44): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(30,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(31,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(32,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(33,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(40,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. +tests/cases/compiler/bigintWithoutLib.ts(40,26): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(41,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. +tests/cases/compiler/bigintWithoutLib.ts(41,26): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(42,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(43,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. +tests/cases/compiler/bigintWithoutLib.ts(43,26): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(44,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. +tests/cases/compiler/bigintWithoutLib.ts(44,26): error TS2736: BigInt literals are not available when targetting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(45,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(46,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(47,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'. @@ -33,7 +45,7 @@ tests/cases/compiler/bigintWithoutLib.ts(48,22): error TS2339: Property 'getBigU tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigUint64' does not exist on type 'DataView'. -==== tests/cases/compiler/bigintWithoutLib.ts (33 errors) ==== +==== tests/cases/compiler/bigintWithoutLib.ts (45 errors) ==== // Every line should error because these builtins are not declared // Test BigInt functions @@ -49,9 +61,13 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU bigintVal = BigInt.asIntN(8, 0xFFFFn); ~~~~~~ !!! error TS2304: Cannot find name 'BigInt'. + ~~~~~~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. bigintVal = BigInt.asUintN(8, 0xFFFFn); ~~~~~~ !!! error TS2304: Cannot find name 'BigInt'. + ~~~~~~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {} ~~~~~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'bigint'. @@ -76,6 +92,12 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU ~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? !!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. bigIntArray = new BigInt64Array([1, 2, 3]); ~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? @@ -105,6 +127,12 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU bigUintArray = new BigUint64Array([1n, 2n, 3n]); ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'BigUint64Array'. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. bigUintArray = new BigUint64Array([1, 2, 3]); ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'BigUint64Array'. @@ -126,18 +154,26 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU dataView.setBigInt64(1, -1n); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. dataView.setBigInt64(1, -1n, true); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. + ~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. dataView.setBigInt64(1, -1); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. dataView.setBigUint64(2, 123n); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. + ~~~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. dataView.setBigUint64(2, 123n, true); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. + ~~~~ +!!! error TS2736: BigInt literals are not available when targetting lower than ESNext. dataView.setBigUint64(2, 123); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. diff --git a/tests/baselines/reference/bigintWithoutLib.js b/tests/baselines/reference/bigintWithoutLib.js index 67265ca8720..31a59fcbaf0 100644 --- a/tests/baselines/reference/bigintWithoutLib.js +++ b/tests/baselines/reference/bigintWithoutLib.js @@ -55,8 +55,8 @@ bigintVal = dataView.getBigUint64(2, true); var bigintVal = BigInt(123); bigintVal = BigInt("456"); new BigInt(123); -bigintVal = BigInt.asIntN(8, 0xFFFFn); -bigintVal = BigInt.asUintN(8, 0xFFFFn); +bigintVal = BigInt.asIntN(8, 0xffffn); +bigintVal = BigInt.asUintN(8, 0xffffn); bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {} var stringVal = bigintVal.toString(); // should not error - bigintVal inferred as {} stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {} diff --git a/tests/baselines/reference/numberVsBigIntOperations.js b/tests/baselines/reference/numberVsBigIntOperations.js index c1d448831dc..9d8a4920d0d 100644 --- a/tests/baselines/reference/numberVsBigIntOperations.js +++ b/tests/baselines/reference/numberVsBigIntOperations.js @@ -96,7 +96,7 @@ if (bigZeroOrOne) isOne(bigZeroOrOne); //// [numberVsBigIntOperations.js] // Cannot mix bigints and numbers -var bigInt = 1n, num = 2; +let bigInt = 1n, num = 2; bigInt = 1n; bigInt = 2; num = 1n; @@ -121,10 +121,10 @@ bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2; -bigInt = Math.pow(bigInt, 1n); -bigInt = Math.pow(bigInt, 2); -num = Math.pow(num, 1n); -num = Math.pow(num, 2); +bigInt **= 1n; +bigInt **= 2; +num **= 1n; +num **= 2; bigInt <<= 1n; bigInt <<= 2; num <<= 1n; @@ -165,10 +165,10 @@ bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2; -bigInt = Math.pow(1n, 2n); -num = Math.pow(1, 2); -Math.pow(1, 2n); -Math.pow(1n, 2); +bigInt = 1n ** 2n; +num = 1 ** 2; +1 ** 2n; +1n ** 2; bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; @@ -190,7 +190,7 @@ num = 1 >> 2; 1 >> 2n; 1n >> 2; // Plus should still coerce to strings -var str; +let str; str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; @@ -217,7 +217,7 @@ num = +bigInt; num = +num; num = +"3"; // Comparisons can be mixed -var result; +let result; result = bigInt > num; result = bigInt >= num; result = bigInt < num; @@ -229,12 +229,12 @@ result = bigInt === num; result = bigInt !== num; // Types of arithmetic operations on other types num = "3" & 5; -num = Math.pow(2, false); // should error, but infer number +num = 2 ** false; // should error, but infer number "3" & 5n; -Math.pow(2n, false); // should error, result in any +2n ** false; // should error, result in any num = ~"3"; num = -false; // should infer number -var bigIntOrNumber; +let bigIntOrNumber; bigIntOrNumber + bigIntOrNumber; // should error, result in any bigIntOrNumber << bigIntOrNumber; // should error, result in any if (typeof bigIntOrNumber === "bigint") { @@ -249,7 +249,7 @@ if (typeof bigIntOrNumber === "number") { ~bigIntOrNumber; // should infer number | bigint bigIntOrNumber++; // should infer number | bigint ++bigIntOrNumber; // should infer number | bigint -var anyValue; +let anyValue; anyValue + anyValue; // should infer any anyValue >>> anyValue; // should infer number anyValue ^ anyValue; // should infer number @@ -258,17 +258,17 @@ anyValue ^ anyValue; // should infer number anyValue--; // should infer number --anyValue; // should infer number // Distinguishing numbers from bigints with typeof -var isBigInt = function (x) { return x; }; -var isNumber = function (x) { return x; }; -var zeroOrBigOne; +const isBigInt = (x) => x; +const isNumber = (x) => x; +const zeroOrBigOne; if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne); else isNumber(zeroOrBigOne); // Distinguishing truthy from falsy -var isOne = function (x) { return x; }; +const isOne = (x) => x; if (zeroOrBigOne) isOne(zeroOrBigOne); -var bigZeroOrOne; +const bigZeroOrOne; if (bigZeroOrOne) isOne(bigZeroOrOne); diff --git a/tests/baselines/reference/parseBigInt.js b/tests/baselines/reference/parseBigInt.js index ccfa3089f0f..1e8b06743d5 100644 --- a/tests/baselines/reference/parseBigInt.js +++ b/tests/baselines/reference/parseBigInt.js @@ -72,73 +72,73 @@ oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3); //// [parseBigInt.js] // All bases should allow "n" suffix -var bin = 5, binBig = 5n; // 5, 5n -var oct = 375, octBig = 375n; // 375, 375n -var hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n -var dec = 123, decBig = 123n; +const bin = 0b101, binBig = 5n; // 5, 5n +const oct = 0o567, octBig = 375n; // 375, 375n +const hex = 0xC0B, hexBig = 0xc0bn; // 3083, 3083n +const dec = 123, decBig = 123n; // Test literals whose values overflow a 53-bit integer // These should be represented exactly in the emitted JS -var largeBin = 384307168202282325n; // 384307168202282325n -var largeOct = 1505852261029722487n; // 1505852261029722487n -var largeDec = 12345678091234567890n; -var largeHex = 0x1234567890abcdefn; // 1311768467294899695n +const largeBin = 384307168202282325n; // 384307168202282325n +const largeOct = 1505852261029722487n; // 1505852261029722487n +const largeDec = 12345678091234567890n; +const largeHex = 0x1234567890abcdefn; // 1311768467294899695n // Test literals with separators -var separatedBin = 21n; // 21n -var separatedOct = 342391n; // 342391n -var separatedDec = 123456789n; -var separatedHex = 0x0abcdefn; // 11259375n +const separatedBin = 21n; // 21n +const separatedOct = 342391n; // 342391n +const separatedDec = 123456789n; +const separatedHex = 0x0abcdefn; // 11259375n // Test parsing literals of different bit sizes // to ensure that parsePseudoBigInt() allocates enough space -var zero = 0n; -var oneBit = 1n; -var twoBit = 3n; // 3n -var threeBit = 7n; // 7n -var fourBit = 15n; // 15n -var fiveBit = 31n; // 31n -var sixBit = 63n; // 63n -var sevenBit = 127n; // 127n -var eightBit = 255n; // 255n -var nineBit = 511n; // 511n -var tenBit = 1023n; // 1023n -var elevenBit = 2047n; // 2047n -var twelveBit = 4095n; // 4095n -var thirteenBit = 8191n; // 8191n -var fourteenBit = 16383n; // 16383n -var fifteenBit = 32767n; // 32767n -var sixteenBit = 65535n; // 65535n -var seventeenBit = 131071n; // 131071n +const zero = 0n; +const oneBit = 1n; +const twoBit = 3n; // 3n +const threeBit = 7n; // 7n +const fourBit = 15n; // 15n +const fiveBit = 31n; // 31n +const sixBit = 63n; // 63n +const sevenBit = 127n; // 127n +const eightBit = 255n; // 255n +const nineBit = 511n; // 511n +const tenBit = 1023n; // 1023n +const elevenBit = 2047n; // 2047n +const twelveBit = 4095n; // 4095n +const thirteenBit = 8191n; // 8191n +const fourteenBit = 16383n; // 16383n +const fifteenBit = 32767n; // 32767n +const sixteenBit = 65535n; // 65535n +const seventeenBit = 131071n; // 131071n // Test negative literals -var neg = -123n; -var negHex = -0x10n; +const neg = -123n; +const negHex = -0x10n; // Test normalization of bigints -- all of these should succeed -var negZero = -0n; -var baseChange = 0xFFn; -var leadingZeros = 0x000000FFn; +const negZero = -0n; +const baseChange = 0xffn; +const leadingZeros = 0x000000ffn; // Plus not allowed on literals -var unaryPlus = +123n; -var unaryPlusHex = +0x123n; +const unaryPlus = +123n; +const unaryPlusHex = +0x123n; // Parsing errors // In separate blocks because they each declare an "n" variable { - var legacyOct = 0123, n; + const legacyOct = 0123, n; } { - var scientific = 1e2, n; + const scientific = 1e2, n; } { - var decimal = 4.1, n; + const decimal = 4.1, n; } { - var leadingDecimal = .1, n; + const leadingDecimal = .1, n; } -var emptyBinary = 0n; // should error but infer 0n -var emptyOct = 0n; // should error but infer 0n -var emptyHex = 0xn; // should error but infer 0n -var leadingSeparator = _123n; -var trailingSeparator = 123n; -var doubleSeparator = 123456789n; +const emptyBinary = 0n; // should error but infer 0n +const emptyOct = 0n; // should error but infer 0n +const emptyHex = 0x0n; // should error but infer 0n +const leadingSeparator = _123n; +const trailingSeparator = 123n; +const doubleSeparator = 123456789n; // Using literals as types -var oneTwoOrThree = function (x) { return Math.pow(x, 2n); }; +const oneTwoOrThree = (x) => x ** 2n; oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); diff --git a/tests/baselines/reference/parseBigInt.types b/tests/baselines/reference/parseBigInt.types index 9e9025b6221..cbf80b69db0 100644 --- a/tests/baselines/reference/parseBigInt.types +++ b/tests/baselines/reference/parseBigInt.types @@ -162,13 +162,13 @@ const leadingZeros: 0xFFn = 0x000000FFn; // Plus not allowed on literals const unaryPlus = +123n; ->unaryPlus : 123n ->+123n : 123n +>unaryPlus : number +>+123n : number >123n : 123n const unaryPlusHex = +0x123n; ->unaryPlusHex : 291n ->+0x123n : 291n +>unaryPlusHex : number +>+0x123n : number >0x123n : 291n // Parsing errors diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 778fb9572f4..7d444ecc45f 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index 16462f9d660..43836a779ad 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -56,7 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ /* Advanced Options */ "noErrorTruncation": true, /* Do not truncate error messages. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index fa8e2c70a66..73e0564f2ad 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 2d2d84b100c..51fd4e44cf9 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index 68329ceecb5..dd8f183c32e 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -56,7 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ }, "files": [ "file0.st", diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index eb13052b37c..de16ddfba0c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 778fb9572f4..7d444ecc45f 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index c9afe008935..587d9941a70 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 37444c9a5de..75621cafebc 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -56,6 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt literals. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/warnExperimentalBigIntLiteral.js b/tests/baselines/reference/warnExperimentalBigIntLiteral.js index 7f31a794ec2..8516350ddbf 100644 --- a/tests/baselines/reference/warnExperimentalBigIntLiteral.js +++ b/tests/baselines/reference/warnExperimentalBigIntLiteral.js @@ -5,7 +5,7 @@ let bigintLiteralType: 123n; // should error when used as type const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error //// [warnExperimentalBigIntLiteral.js] -var normalNumber = 123; // should not error -var bigintType; // should not error -var bigintLiteralType; // should error when used as type -var bigintNumber = 123n * 15n + 292n * 0x7fn; // each literal should error +const normalNumber = 123; // should not error +let bigintType; // should not error +let bigintLiteralType; // should error when used as type +const bigintNumber = 123n * 15n + 292n * 0x7fn; // each literal should error diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index ca467d58c0e..17a4db01778 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -1,4 +1,4 @@ -// @target: es2015 +// @target: esnext // @experimentalBigInt: true interface BigIntIndex { diff --git a/tests/cases/compiler/numberVsBigIntOperations.ts b/tests/cases/compiler/numberVsBigIntOperations.ts index b2f337b00b9..e6b87e57e13 100644 --- a/tests/cases/compiler/numberVsBigIntOperations.ts +++ b/tests/cases/compiler/numberVsBigIntOperations.ts @@ -1,4 +1,5 @@ // @experimentalBigInt: true +// @target: esnext // Cannot mix bigints and numbers let bigInt = 1n, num = 2; diff --git a/tests/cases/compiler/parseBigInt.ts b/tests/cases/compiler/parseBigInt.ts index 35cc13151ad..05ee6bfd7ac 100644 --- a/tests/cases/compiler/parseBigInt.ts +++ b/tests/cases/compiler/parseBigInt.ts @@ -1,4 +1,5 @@ // @experimentalBigInt: true +// @target: esnext // All bases should allow "n" suffix const bin = 0b101, binBig = 0b101n; // 5, 5n diff --git a/tests/cases/compiler/warnExperimentalBigIntLiteral.ts b/tests/cases/compiler/warnExperimentalBigIntLiteral.ts index 2b4954bef3d..c9f94fcc992 100644 --- a/tests/cases/compiler/warnExperimentalBigIntLiteral.ts +++ b/tests/cases/compiler/warnExperimentalBigIntLiteral.ts @@ -1,3 +1,5 @@ +// @target: esnext + const normalNumber = 123; // should not error let bigintType: bigint; // should not error let bigintLiteralType: 123n; // should error when used as type