From 592396d40a250147a4637a8db9376ffa0a90ebaf Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 22 Feb 2019 07:09:37 +0800 Subject: [PATCH] expose token flags and numeric flags (#29897) * expose token flags and numeric flags * hide hide useless token flags --- src/compiler/factory.ts | 4 ++-- src/compiler/types.ts | 8 +++++++- tests/baselines/reference/api/tsserverlibrary.d.ts | 10 +++++++++- tests/baselines/reference/api/typescript.d.ts | 10 +++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 00d84192055..f303dcb47a6 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -89,10 +89,10 @@ namespace ts { return createLiteralFromNode(value); } - export function createNumericLiteral(value: string): NumericLiteral { + export function createNumericLiteral(value: string, numericLiteralFlags: TokenFlags = TokenFlags.None): NumericLiteral { const node = createSynthesizedNode(SyntaxKind.NumericLiteral); node.text = value; - node.numericLiteralFlags = 0; + node.numericLiteralFlags = numericLiteralFlags; return node; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c0ae3b99c44..cce869df44e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1648,20 +1648,26 @@ namespace ts { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } - /* @internal */ export const enum TokenFlags { None = 0, + /* @internal */ PrecedingLineBreak = 1 << 0, + /* @internal */ PrecedingJSDocComment = 1 << 1, + /* @internal */ Unterminated = 1 << 2, + /* @internal */ ExtendedUnicodeEscape = 1 << 3, Scientific = 1 << 4, // e.g. `10e2` Octal = 1 << 5, // e.g. `0777` HexSpecifier = 1 << 6, // e.g. `0x00000000` BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000` OctalSpecifier = 1 << 8, // e.g. `0o777` + /* @internal */ ContainsSeparator = 1 << 9, // e.g. `0b1100_0101` + /* @internal */ BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier, + /* @internal */ NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinaryOrOctalSpecifier | ContainsSeparator } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 36c246c999f..fab6f905efc 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -997,6 +997,14 @@ declare namespace ts { interface NoSubstitutionTemplateLiteral extends LiteralExpression { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } + enum TokenFlags { + None = 0, + Scientific = 16, + Octal = 32, + HexSpecifier = 64, + BinarySpecifier = 128, + OctalSpecifier = 256 + } interface NumericLiteral extends LiteralExpression { kind: SyntaxKind.NumericLiteral; } @@ -3670,7 +3678,7 @@ declare namespace ts { function createLiteral(value: number | PseudoBigInt): NumericLiteral; function createLiteral(value: boolean): BooleanLiteral; function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression; - function createNumericLiteral(value: string): NumericLiteral; + function createNumericLiteral(value: string, numericLiteralFlags?: TokenFlags): NumericLiteral; function createBigIntLiteral(value: string): BigIntLiteral; function createStringLiteral(text: string): StringLiteral; function createRegularExpressionLiteral(text: string): RegularExpressionLiteral; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 15dbc080241..40e16bf55bd 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -997,6 +997,14 @@ declare namespace ts { interface NoSubstitutionTemplateLiteral extends LiteralExpression { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } + enum TokenFlags { + None = 0, + Scientific = 16, + Octal = 32, + HexSpecifier = 64, + BinarySpecifier = 128, + OctalSpecifier = 256 + } interface NumericLiteral extends LiteralExpression { kind: SyntaxKind.NumericLiteral; } @@ -3670,7 +3678,7 @@ declare namespace ts { function createLiteral(value: number | PseudoBigInt): NumericLiteral; function createLiteral(value: boolean): BooleanLiteral; function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression; - function createNumericLiteral(value: string): NumericLiteral; + function createNumericLiteral(value: string, numericLiteralFlags?: TokenFlags): NumericLiteral; function createBigIntLiteral(value: string): BigIntLiteral; function createStringLiteral(text: string): StringLiteral; function createRegularExpressionLiteral(text: string): RegularExpressionLiteral;