Skip to content

Commit df4a300

Browse files
committed
✨ change the default ecma version.
1 parent 2bd358f commit df4a300

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

src/ecma-versions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type EcmaVersion = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020

src/parser.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Pattern,
1313
Quantifier,
1414
} from "./ast"
15+
import { EcmaVersion } from "./ecma-versions"
1516
import { HyphenMinus } from "./unicode"
1617
import { RegExpValidator } from "./validator"
1718

@@ -29,7 +30,7 @@ const DummyCapturingGroup: CapturingGroup = {} as any
2930

3031
class RegExpParserState {
3132
public readonly strict: boolean
32-
public readonly ecmaVersion: 5 | 2015 | 2016 | 2017 | 2018
33+
public readonly ecmaVersion: EcmaVersion
3334
private _node: AppendableNode = DummyPattern
3435
private _flags: Flags = DummyFlags
3536
private _backreferences: Backreference[] = []
@@ -39,7 +40,7 @@ class RegExpParserState {
3940

4041
public constructor(options?: RegExpParser.Options) {
4142
this.strict = Boolean(options && options.strict)
42-
this.ecmaVersion = (options && options.ecmaVersion) || 2018
43+
this.ecmaVersion = (options && options.ecmaVersion) || 2020
4344
}
4445

4546
public get pattern(): Pattern {
@@ -501,12 +502,13 @@ export namespace RegExpParser {
501502
strict?: boolean
502503

503504
/**
504-
* ECMAScript version. Default is `2018`.
505+
* ECMAScript version. Default is `2020`.
505506
* - `2015` added `u` and `y` flags.
506507
* - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
507508
* and Unicode Property Escape.
509+
* - `2019` and `2020` added more valid Unicode Property Escapes.
508510
*/
509-
ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018
511+
ecmaVersion?: EcmaVersion
510512
}
511513
}
512514

src/util.ts

-9
This file was deleted.

src/validator.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { EcmaVersion } from "./ecma-versions"
12
import { Reader } from "./reader"
23
import { RegExpSyntaxError } from "./regexp-syntax-error"
34
import {
@@ -123,12 +124,13 @@ export namespace RegExpValidator {
123124
strict?: boolean
124125

125126
/**
126-
* ECMAScript version. Default is `2018`.
127+
* ECMAScript version. Default is `2020`.
127128
* - `2015` added `u` and `y` flags.
128129
* - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
129130
* and Unicode Property Escape.
131+
* - `2019` and `2020` added more valid Unicode Property Escapes.
130132
*/
131-
ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018
133+
ecmaVersion?: EcmaVersion
132134

133135
/**
134136
* A function that is called when the validator entered a RegExp literal.
@@ -543,7 +545,7 @@ export class RegExpValidator {
543545
}
544546

545547
private get ecmaVersion() {
546-
return this._options.ecmaVersion || 2018
548+
return this._options.ecmaVersion || 2020
547549
}
548550

549551
private onLiteralEnter(start: number): void {

0 commit comments

Comments
 (0)