Skip to content

Commit

Permalink
fix(lexer): store correct bigint token value
Browse files Browse the repository at this point in the history
closes #93
BREAKING CHANGE: upgraded ts target from es2018 to es2020, dropped nodejs v6 and v8 support
  • Loading branch information
3cp committed Sep 17, 2020
1 parent c9f441c commit 964e678
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ jobs:
- run: npm ci
- run: npm run bundle

test-8:
<<: *test
executor:
name: docker-circleci
node: "8.16.1"

test-10:
<<: *test
executor:
Expand Down Expand Up @@ -150,8 +144,6 @@ workflows:
<<: *filter_ignore_dev
- bundle:
<<: *filter_ignore_dev
- test-8:
<<: *filter_ignore_dev
- test-10:
<<: *filter_ignore_dev
- test-12:
Expand All @@ -171,14 +163,12 @@ workflows:
- build
- lint
- bundle
- test-8
- test-10
- test-12
- merge_and_dist:
requires:
- build
- lint
- bundle
- test-8
- test-10
- test-12
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@
}
},
"engines": {
"node": ">=6.0.0"
"node": ">=10.4.0"
}
}
2 changes: 1 addition & 1 deletion src/lexer/numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function scanNumber(parser: ParserState, context: Context, kind: NumberKi

if (isBigInt) {
parser.tokenRaw = parser.source.slice(parser.tokenPos, parser.index);
parser.tokenValue = parseInt(value, 0xa);
parser.tokenValue = BigInt(value);
return Token.BigIntLiteral;
}

Expand Down
26 changes: 16 additions & 10 deletions test/lexer/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { create } from '../../src/parser';
import { scanSingleToken } from '../../src/lexer/scan';

describe('Lexer - Numberic literals', () => {
const tokens: [Context, Token, string, number][] = [
const tokens: [Context, Token, string, number | bigint][] = [
// Numeric literals
[Context.None, Token.NumericLiteral, '0', 0],
[Context.None, Token.NumericLiteral, '1', 1],
Expand Down Expand Up @@ -151,15 +151,21 @@ describe('Lexer - Numberic literals', () => {
[Context.None, Token.NumericLiteral, '0000000000234567454548', 234567454548],

// BigInt
[Context.None, Token.BigIntLiteral, '1n', 1],
[Context.None, Token.BigIntLiteral, '0o45n', 37],
[Context.None, Token.BigIntLiteral, '0b10n', 2],
[Context.None, Token.BigIntLiteral, '0x9an', 154],
[Context.None, Token.BigIntLiteral, '9007199254740991n', 9007199254740991],
[Context.None, Token.BigIntLiteral, '100000000000000000n', 100000000000000000],
[Context.OptionsRaw, Token.BigIntLiteral, '123456789000000000000000n', 123456789000000000000000],
[Context.None, Token.BigIntLiteral, '0xfn', 15],
[Context.None, Token.BigIntLiteral, '0n', 0],
[Context.None, Token.BigIntLiteral, '1n', BigInt(1)],
[Context.None, Token.BigIntLiteral, '0o45n', BigInt(37)],
[Context.None, Token.BigIntLiteral, '0b10n', BigInt(2)],
[Context.None, Token.BigIntLiteral, '0x9an', BigInt(154)],
[Context.None, Token.BigIntLiteral, '9007199254740991n', BigInt(9007199254740991)],
[Context.None, Token.BigIntLiteral, '100000000000000000n', BigInt(100000000000000000)],
[Context.OptionsRaw, Token.BigIntLiteral, '123456789000000000000000n', BigInt('123456789000000000000000')],
[Context.None, Token.BigIntLiteral, '0xfn', BigInt(15)],
[Context.None, Token.BigIntLiteral, '0n', BigInt(0)],
[
Context.None,
Token.BigIntLiteral,
'0x12300000000000000000000000000000000n',
BigInt('99022168773993092867842010762644549533696')
],

// Numeric separators
[Context.OptionsRaw, Token.NumericLiteral, '0', 0],
Expand Down
6 changes: 3 additions & 3 deletions test/parser/expressions/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Expressions - BigInt', () => {
type: 'ExpressionStatement',
expression: {
type: 'BigIntLiteral',
value: 1,
value: BigInt(1),
bigint: '1n',
start: 0,
end: 2,
Expand Down Expand Up @@ -182,15 +182,15 @@ describe('Expressions - BigInt', () => {
type: 'BinaryExpression',
left: {
type: 'BigIntLiteral',
value: 1,
value: BigInt(1),
bigint: '1n',
start: 0,
end: 2,
range: [0, 2]
},
right: {
type: 'BigIntLiteral',
value: 2333333,
value: BigInt(2333333),
bigint: '2333333n',
start: 5,
end: 13,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"sourceMap": true,
"strict": true,
"stripInternal": true,
"target": "es2018",
"target": "ES2020",
"typeRoots": ["./node_modules/@types"],
"types": ["node", "mocha"]
},
Expand Down

0 comments on commit 964e678

Please sign in to comment.