Skip to content

Commit 59f5774

Browse files
authored
chore: refactor internal variables (#49)
1 parent c5696d6 commit 59f5774

File tree

10 files changed

+332
-311
lines changed

10 files changed

+332
-311
lines changed

.eslintrc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ module.exports = {
2626
// https://github.com/typescript-eslint/typescript-eslint/issues/743
2727
"@eslint-community/mysticatea/ts/unbound-method": "off",
2828

29-
// Temporary disabled rules
30-
"@eslint-community/mysticatea/ts/naming-convention": "off",
29+
// Temporary disabled rule: Making a type stricter requires a breaking change of the types.
3130
"@eslint-community/mysticatea/ts/prefer-readonly-parameter-types":
3231
"off",
3332
// Should be fixed by `@eslint-community/eslint-plugin-mysticatea`

scripts/update-fixtures.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as Parser from "../test/fixtures/parser/literal"
55
import * as Visitor from "../test/fixtures/visitor"
66
import { cloneWithoutCircular } from "./clone-without-circular"
77

8-
for (const filename of Object.keys(Parser.Fixtures)) {
9-
const fixture = Parser.Fixtures[filename]
8+
for (const filename of Object.keys(Parser.fixturesData)) {
9+
const fixture = Parser.fixturesData[filename]
1010
const options = fixture.options
1111

1212
for (const pattern of Object.keys(fixture.patterns)) {
@@ -24,8 +24,8 @@ for (const filename of Object.keys(Parser.Fixtures)) {
2424
Parser.save()
2525
}
2626

27-
for (const filename of Object.keys(Visitor.Fixtures)) {
28-
const fixture = Visitor.Fixtures[filename]
27+
for (const filename of Object.keys(Visitor.fixturesData)) {
28+
const fixture = Visitor.fixturesData[filename]
2929
const options = fixture.options
3030

3131
for (const pattern of Object.keys(fixture.patterns)) {

scripts/update-unicode-properties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { DOMWindow } from "jsdom"
33
import { JSDOM } from "jsdom"
44
import { ESLint } from "eslint"
55

6-
const DataSources = [
6+
const DATA_SOURCES = [
77
{
88
url: "https://262.ecma-international.org/9.0",
99
version: 2018,
@@ -71,7 +71,7 @@ type Datum = {
7171
scValues,
7272
url,
7373
version,
74-
} of DataSources) {
74+
} of DATA_SOURCES) {
7575
logger.log("---- ECMAScript %d ----", version)
7676
const datum: Datum = {
7777
binProperties: [],

src/parser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
Quantifier,
1414
} from "./ast"
1515
import type { EcmaVersion } from "./ecma-versions"
16-
import { HyphenMinus } from "./unicode"
16+
import { HYPHEN_MINUS } from "./unicode"
1717
import { RegExpValidator } from "./validator"
1818

1919
type AppendableNode =
@@ -24,18 +24,18 @@ type AppendableNode =
2424
| LookaroundAssertion
2525
| Pattern
2626

27-
const DummyPattern: Pattern = {} as Pattern
28-
const DummyFlags: Flags = {} as Flags
29-
const DummyCapturingGroup: CapturingGroup = {} as CapturingGroup
27+
const DUMMY_PATTERN: Pattern = {} as Pattern
28+
const DUMMY_FLAGS: Flags = {} as Flags
29+
const DUMMY_CAPTURING_GROUP: CapturingGroup = {} as CapturingGroup
3030

3131
class RegExpParserState {
3232
public readonly strict: boolean
3333

3434
public readonly ecmaVersion: EcmaVersion
3535

36-
private _node: AppendableNode = DummyPattern
36+
private _node: AppendableNode = DUMMY_PATTERN
3737

38-
private _flags: Flags = DummyFlags
38+
private _flags: Flags = DUMMY_FLAGS
3939

4040
private _backreferences: Backreference[] = []
4141

@@ -422,7 +422,7 @@ class RegExpParserState {
422422
end,
423423
raw: this.source.slice(start, end),
424424
ref,
425-
resolved: DummyCapturingGroup,
425+
resolved: DUMMY_CAPTURING_GROUP,
426426
}
427427
parent.elements.push(node)
428428
this._backreferences.push(node)
@@ -478,7 +478,7 @@ class RegExpParserState {
478478
min.type !== "Character" ||
479479
max.type !== "Character" ||
480480
hyphen.type !== "Character" ||
481-
hyphen.value !== HyphenMinus
481+
hyphen.value !== HYPHEN_MINUS
482482
) {
483483
throw new Error("UnknownError")
484484
}

src/unicode/index.ts

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,120 +4,120 @@ export {
44
isValidUnicodeProperty,
55
} from "./properties"
66

7-
export const Null = 0x00
8-
export const Backspace = 0x08
9-
export const CharacterTabulation = 0x09
10-
export const LineFeed = 0x0a
11-
export const LineTabulation = 0x0b
12-
export const FormFeed = 0x0c
13-
export const CarriageReturn = 0x0d
14-
export const ExclamationMark = 0x21
15-
export const DollarSign = 0x24
16-
export const LeftParenthesis = 0x28
17-
export const RightParenthesis = 0x29
18-
export const Asterisk = 0x2a
19-
export const PlusSign = 0x2b
20-
export const Comma = 0x2c
21-
export const HyphenMinus = 0x2d
22-
export const FullStop = 0x2e
23-
export const Solidus = 0x2f
24-
export const DigitZero = 0x30
25-
export const DigitOne = 0x31
26-
export const DigitSeven = 0x37
27-
export const DigitNine = 0x39
28-
export const Colon = 0x3a
29-
export const LessThanSign = 0x3c
30-
export const EqualsSign = 0x3d
31-
export const GreaterThanSign = 0x3e
32-
export const QuestionMark = 0x3f
33-
export const LatinCapitalLetterA = 0x41
34-
export const LatinCapitalLetterB = 0x42
35-
export const LatinCapitalLetterD = 0x44
36-
export const LatinCapitalLetterF = 0x46
37-
export const LatinCapitalLetterP = 0x50
38-
export const LatinCapitalLetterS = 0x53
39-
export const LatinCapitalLetterW = 0x57
40-
export const LatinCapitalLetterZ = 0x5a
41-
export const LowLine = 0x5f
42-
export const LatinSmallLetterA = 0x61
43-
export const LatinSmallLetterB = 0x62
44-
export const LatinSmallLetterC = 0x63
45-
export const LatinSmallLetterD = 0x64
46-
export const LatinSmallLetterF = 0x66
47-
export const LatinSmallLetterG = 0x67
48-
export const LatinSmallLetterI = 0x69
49-
export const LatinSmallLetterK = 0x6b
50-
export const LatinSmallLetterM = 0x6d
51-
export const LatinSmallLetterN = 0x6e
52-
export const LatinSmallLetterP = 0x70
53-
export const LatinSmallLetterR = 0x72
54-
export const LatinSmallLetterS = 0x73
55-
export const LatinSmallLetterT = 0x74
56-
export const LatinSmallLetterU = 0x75
57-
export const LatinSmallLetterV = 0x76
58-
export const LatinSmallLetterW = 0x77
59-
export const LatinSmallLetterX = 0x78
60-
export const LatinSmallLetterY = 0x79
61-
export const LatinSmallLetterZ = 0x7a
62-
export const LeftSquareBracket = 0x5b
63-
export const ReverseSolidus = 0x5c
64-
export const RightSquareBracket = 0x5d
65-
export const CircumflexAccent = 0x5e
66-
export const LeftCurlyBracket = 0x7b
67-
export const VerticalLine = 0x7c
68-
export const RightCurlyBracket = 0x7d
69-
export const ZeroWidthNonJoiner = 0x200c
70-
export const ZeroWidthJoiner = 0x200d
71-
export const LineSeparator = 0x2028
72-
export const ParagraphSeparator = 0x2029
7+
export const NULL = 0x00
8+
export const BACKSPACE = 0x08
9+
export const CHARACTER_TABULATION = 0x09
10+
export const LINE_FEED = 0x0a
11+
export const LINE_TABULATION = 0x0b
12+
export const FORM_FEED = 0x0c
13+
export const CARRIAGE_RETURN = 0x0d
14+
export const EXCLAMATION_MARK = 0x21
15+
export const DOLLAR_SIGN = 0x24
16+
export const LEFT_PARENTHESIS = 0x28
17+
export const RIGHT_PARENTHESIS = 0x29
18+
export const ASTERISK = 0x2a
19+
export const PLUS_SIGN = 0x2b
20+
export const COMMA = 0x2c
21+
export const HYPHEN_MINUS = 0x2d
22+
export const FULL_STOP = 0x2e
23+
export const SOLIDUS = 0x2f
24+
export const DIGIT_ZERO = 0x30
25+
export const DIGIT_ONE = 0x31
26+
export const DIGIT_SEVEN = 0x37
27+
export const DIGIT_NINE = 0x39
28+
export const COLON = 0x3a
29+
export const LESS_THAN_SIGN = 0x3c
30+
export const EQUALS_SIGN = 0x3d
31+
export const GREATER_THAN_SIGN = 0x3e
32+
export const QUESTION_MARK = 0x3f
33+
export const LATIN_CAPITAL_LETTER_A = 0x41
34+
export const LATIN_CAPITAL_LETTER_B = 0x42
35+
export const LATIN_CAPITAL_LETTER_D = 0x44
36+
export const LATIN_CAPITAL_LETTER_F = 0x46
37+
export const LATIN_CAPITAL_LETTER_P = 0x50
38+
export const LATIN_CAPITAL_LETTER_S = 0x53
39+
export const LATIN_CAPITAL_LETTER_W = 0x57
40+
export const LATIN_CAPITAL_LETTER_Z = 0x5a
41+
export const LOW_LINE = 0x5f
42+
export const LATIN_SMALL_LETTER_A = 0x61
43+
export const LATIN_SMALL_LETTER_B = 0x62
44+
export const LATIN_SMALL_LETTER_C = 0x63
45+
export const LATIN_SMALL_LETTER_D = 0x64
46+
export const LATIN_SMALL_LETTER_F = 0x66
47+
export const LATIN_SMALL_LETTER_G = 0x67
48+
export const LATIN_SMALL_LETTER_I = 0x69
49+
export const LATIN_SMALL_LETTER_K = 0x6b
50+
export const LATIN_SMALL_LETTER_M = 0x6d
51+
export const LATIN_SMALL_LETTER_N = 0x6e
52+
export const LATIN_SMALL_LETTER_P = 0x70
53+
export const LATIN_SMALL_LETTER_R = 0x72
54+
export const LATIN_SMALL_LETTER_S = 0x73
55+
export const LATIN_SMALL_LETTER_T = 0x74
56+
export const LATIN_SMALL_LETTER_U = 0x75
57+
export const LATIN_SMALL_LETTER_V = 0x76
58+
export const LATIN_SMALL_LETTER_W = 0x77
59+
export const LATIN_SMALL_LETTER_X = 0x78
60+
export const LATIN_SMALL_LETTER_Y = 0x79
61+
export const LATIN_SMALL_LETTER_Z = 0x7a
62+
export const LEFT_SQUARE_BRACKET = 0x5b
63+
export const REVERSE_SOLIDUS = 0x5c
64+
export const RIGHT_SQUARE_BRACKET = 0x5d
65+
export const CIRCUMFLEX_ACCENT = 0x5e
66+
export const LEFT_CURLY_BRACKET = 0x7b
67+
export const VERTICAL_LINE = 0x7c
68+
export const RIGHT_CURLY_BRACKET = 0x7d
69+
export const ZERO_WIDTH_NON_JOINER = 0x200c
70+
export const ZERO_WIDTH_JOINER = 0x200d
71+
export const LINE_SEPARATOR = 0x2028
72+
export const PARAGRAPH_SEPARATOR = 0x2029
7373

74-
export const MinCodePoint = 0x00
75-
export const MaxCodePoint = 0x10ffff
74+
export const MIN_CODE_POINT = 0x00
75+
export const MAX_CODE_POINT = 0x10ffff
7676

7777
export function isLatinLetter(code: number): boolean {
7878
return (
79-
(code >= LatinCapitalLetterA && code <= LatinCapitalLetterZ) ||
80-
(code >= LatinSmallLetterA && code <= LatinSmallLetterZ)
79+
(code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
80+
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z)
8181
)
8282
}
8383

8484
export function isDecimalDigit(code: number): boolean {
85-
return code >= DigitZero && code <= DigitNine
85+
return code >= DIGIT_ZERO && code <= DIGIT_NINE
8686
}
8787

8888
export function isOctalDigit(code: number): boolean {
89-
return code >= DigitZero && code <= DigitSeven
89+
return code >= DIGIT_ZERO && code <= DIGIT_SEVEN
9090
}
9191

9292
export function isHexDigit(code: number): boolean {
9393
return (
94-
(code >= DigitZero && code <= DigitNine) ||
95-
(code >= LatinCapitalLetterA && code <= LatinCapitalLetterF) ||
96-
(code >= LatinSmallLetterA && code <= LatinSmallLetterF)
94+
(code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
95+
(code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
96+
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F)
9797
)
9898
}
9999

100100
export function isLineTerminator(code: number): boolean {
101101
return (
102-
code === LineFeed ||
103-
code === CarriageReturn ||
104-
code === LineSeparator ||
105-
code === ParagraphSeparator
102+
code === LINE_FEED ||
103+
code === CARRIAGE_RETURN ||
104+
code === LINE_SEPARATOR ||
105+
code === PARAGRAPH_SEPARATOR
106106
)
107107
}
108108

109109
export function isValidUnicode(code: number): boolean {
110-
return code >= MinCodePoint && code <= MaxCodePoint
110+
return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT
111111
}
112112

113113
export function digitToInt(code: number): number {
114-
if (code >= LatinSmallLetterA && code <= LatinSmallLetterF) {
115-
return code - LatinSmallLetterA + 10
114+
if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
115+
return code - LATIN_SMALL_LETTER_A + 10
116116
}
117-
if (code >= LatinCapitalLetterA && code <= LatinCapitalLetterF) {
118-
return code - LatinCapitalLetterA + 10
117+
if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
118+
return code - LATIN_CAPITAL_LETTER_A + 10
119119
}
120-
return code - DigitZero
120+
return code - DIGIT_ZERO
121121
}
122122

123123
export function isLeadSurrogate(code: number): boolean {

0 commit comments

Comments
 (0)