Skip to content

Commit 592396d

Browse files
Kingwlweswigham
authored andcommitted
expose token flags and numeric flags (microsoft#29897)
* expose token flags and numeric flags * hide hide useless token flags
1 parent ae836eb commit 592396d

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ namespace ts {
8989
return createLiteralFromNode(value);
9090
}
9191

92-
export function createNumericLiteral(value: string): NumericLiteral {
92+
export function createNumericLiteral(value: string, numericLiteralFlags: TokenFlags = TokenFlags.None): NumericLiteral {
9393
const node = <NumericLiteral>createSynthesizedNode(SyntaxKind.NumericLiteral);
9494
node.text = value;
95-
node.numericLiteralFlags = 0;
95+
node.numericLiteralFlags = numericLiteralFlags;
9696
return node;
9797
}
9898

src/compiler/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,20 +1648,26 @@ namespace ts {
16481648
kind: SyntaxKind.NoSubstitutionTemplateLiteral;
16491649
}
16501650

1651-
/* @internal */
16521651
export const enum TokenFlags {
16531652
None = 0,
1653+
/* @internal */
16541654
PrecedingLineBreak = 1 << 0,
1655+
/* @internal */
16551656
PrecedingJSDocComment = 1 << 1,
1657+
/* @internal */
16561658
Unterminated = 1 << 2,
1659+
/* @internal */
16571660
ExtendedUnicodeEscape = 1 << 3,
16581661
Scientific = 1 << 4, // e.g. `10e2`
16591662
Octal = 1 << 5, // e.g. `0777`
16601663
HexSpecifier = 1 << 6, // e.g. `0x00000000`
16611664
BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000`
16621665
OctalSpecifier = 1 << 8, // e.g. `0o777`
1666+
/* @internal */
16631667
ContainsSeparator = 1 << 9, // e.g. `0b1100_0101`
1668+
/* @internal */
16641669
BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier,
1670+
/* @internal */
16651671
NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinaryOrOctalSpecifier | ContainsSeparator
16661672
}
16671673

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,14 @@ declare namespace ts {
997997
interface NoSubstitutionTemplateLiteral extends LiteralExpression {
998998
kind: SyntaxKind.NoSubstitutionTemplateLiteral;
999999
}
1000+
enum TokenFlags {
1001+
None = 0,
1002+
Scientific = 16,
1003+
Octal = 32,
1004+
HexSpecifier = 64,
1005+
BinarySpecifier = 128,
1006+
OctalSpecifier = 256
1007+
}
10001008
interface NumericLiteral extends LiteralExpression {
10011009
kind: SyntaxKind.NumericLiteral;
10021010
}
@@ -3670,7 +3678,7 @@ declare namespace ts {
36703678
function createLiteral(value: number | PseudoBigInt): NumericLiteral;
36713679
function createLiteral(value: boolean): BooleanLiteral;
36723680
function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression;
3673-
function createNumericLiteral(value: string): NumericLiteral;
3681+
function createNumericLiteral(value: string, numericLiteralFlags?: TokenFlags): NumericLiteral;
36743682
function createBigIntLiteral(value: string): BigIntLiteral;
36753683
function createStringLiteral(text: string): StringLiteral;
36763684
function createRegularExpressionLiteral(text: string): RegularExpressionLiteral;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,14 @@ declare namespace ts {
997997
interface NoSubstitutionTemplateLiteral extends LiteralExpression {
998998
kind: SyntaxKind.NoSubstitutionTemplateLiteral;
999999
}
1000+
enum TokenFlags {
1001+
None = 0,
1002+
Scientific = 16,
1003+
Octal = 32,
1004+
HexSpecifier = 64,
1005+
BinarySpecifier = 128,
1006+
OctalSpecifier = 256
1007+
}
10001008
interface NumericLiteral extends LiteralExpression {
10011009
kind: SyntaxKind.NumericLiteral;
10021010
}
@@ -3670,7 +3678,7 @@ declare namespace ts {
36703678
function createLiteral(value: number | PseudoBigInt): NumericLiteral;
36713679
function createLiteral(value: boolean): BooleanLiteral;
36723680
function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression;
3673-
function createNumericLiteral(value: string): NumericLiteral;
3681+
function createNumericLiteral(value: string, numericLiteralFlags?: TokenFlags): NumericLiteral;
36743682
function createBigIntLiteral(value: string): BigIntLiteral;
36753683
function createStringLiteral(text: string): StringLiteral;
36763684
function createRegularExpressionLiteral(text: string): RegularExpressionLiteral;

0 commit comments

Comments
 (0)