Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

[JS/TS] Add support for BigInt #62

Merged
merged 1 commit into from Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 90 additions & 0 deletions src/javascript/javascript.test.ts
Expand Up @@ -396,6 +396,96 @@ testTokenization('javascript', [
]
}],

// Bigint
[{
line: '0n',
tokens: [
{ startIndex: 0, type: 'number.js' }
]
}],

[{
line: ' 0n',
tokens: [
{ startIndex: 0, type: '' },
{ startIndex: 1, type: 'number.js' }
]
}],

[{
line: ' 0n ',
tokens: [
{ startIndex: 0, type: '' },
{ startIndex: 1, type: 'number.js' },
{ startIndex: 3, type: '' }
]
}],

[{
line: '0n ',
tokens: [
{ startIndex: 0, type: 'number.js' },
{ startIndex: 2, type: '' }
]
}],

[{
line: '0n+0n',
tokens: [
{ startIndex: 0, type: 'number.js' },
{ startIndex: 2, type: 'delimiter.js' },
{ startIndex: 3, type: 'number.js' }
]
}],

[{
line: '100n+10n',
tokens: [
{ startIndex: 0, type: 'number.js' },
{ startIndex: 4, type: 'delimiter.js' },
{ startIndex: 5, type: 'number.js' }
]
}],

[{
line: '0n + 0n',
tokens: [
{ startIndex: 0, type: 'number.js' },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'delimiter.js' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'number.js' }
]
}],

[{
line: '0b101n',
tokens: [
{ startIndex: 0, type: 'number.binary.js' }
]
}],

[{
line: '0123n',
tokens: [
{ startIndex: 0, type: 'number.octal.js' }
]
}],

[{
line: '0o123n',
tokens: [
{ startIndex: 0, type: 'number.octal.js' }
]
}],

[{
line: '0x123n',
tokens: [
{ startIndex: 0, type: 'number.hex.js' }
]
}],

// Regular Expressions
[{
line: '//',
Expand Down
90 changes: 90 additions & 0 deletions src/typescript/typescript.test.ts
Expand Up @@ -396,6 +396,96 @@ testTokenization('typescript', [
]
}],

// Bigint
[{
line: '0n',
tokens: [
{ startIndex: 0, type: 'number.ts' }
]
}],

[{
line: ' 0n',
tokens: [
{ startIndex: 0, type: '' },
{ startIndex: 1, type: 'number.ts' }
]
}],

[{
line: ' 0n ',
tokens: [
{ startIndex: 0, type: '' },
{ startIndex: 1, type: 'number.ts' },
{ startIndex: 3, type: '' }
]
}],

[{
line: '0n ',
tokens: [
{ startIndex: 0, type: 'number.ts' },
{ startIndex: 2, type: '' }
]
}],

[{
line: '0n+0n',
tokens: [
{ startIndex: 0, type: 'number.ts' },
{ startIndex: 2, type: 'delimiter.ts' },
{ startIndex: 3, type: 'number.ts' }
]
}],

[{
line: '100n+10n',
tokens: [
{ startIndex: 0, type: 'number.ts' },
{ startIndex: 4, type: 'delimiter.ts' },
{ startIndex: 5, type: 'number.ts' }
]
}],

[{
line: '0n + 0n',
tokens: [
{ startIndex: 0, type: 'number.ts' },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'delimiter.ts' },
{ startIndex: 4, type: '' },
{ startIndex: 5, type: 'number.ts' }
]
}],

[{
line: '0b101n',
tokens: [
{ startIndex: 0, type: 'number.binary.ts' }
]
}],

[{
line: '0123n',
tokens: [
{ startIndex: 0, type: 'number.octal.ts' }
]
}],

[{
line: '0o123n',
tokens: [
{ startIndex: 0, type: 'number.octal.ts' }
]
}],

[{
line: '0x123n',
tokens: [
{ startIndex: 0, type: 'number.hex.ts' }
]
}],

// Regular Expressions
[{
line: '//',
Expand Down
8 changes: 4 additions & 4 deletions src/typescript/typescript.ts
Expand Up @@ -146,10 +146,10 @@ export const language = {
// numbers
[/(@digits)[eE]([\-+]?(@digits))?/, 'number.float'],
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, 'number.float'],
[/0[xX](@hexdigits)/, 'number.hex'],
[/0[oO]?(@octaldigits)/, 'number.octal'],
[/0[bB](@binarydigits)/, 'number.binary'],
[/(@digits)/, 'number'],
[/0[xX](@hexdigits)n?/, 'number.hex'],
[/0[oO]?(@octaldigits)n?/, 'number.octal'],
[/0[bB](@binarydigits)n?/, 'number.binary'],
[/(@digits)n?/, 'number'],

// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
Expand Down