Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb58633

Browse files
authored
refactor (#246)
1 parent 769da24 commit bb58633

27 files changed

+153
-195
lines changed

scripts/update-fixtures-ast.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ for (const name of TARGETS) {
102102
const servicesPath = path.join(ROOT, `${name}/services.json`)
103103
const source = fs.readFileSync(sourcePath, "utf8")
104104
const parserOptions = optionsPath ? require(optionsPath) : {}
105-
const options = Object.assign(
106-
{ filePath: sourcePath },
107-
PARSER_OPTIONS,
108-
parserOptions,
109-
)
105+
const options = {
106+
filePath: sourcePath,
107+
...PARSER_OPTIONS,
108+
...parserOptions,
109+
}
110110
// console.log("Start:", name)
111111
const actual = parser.parseForESLint(source, options)
112112
const tokenRanges = getAllTokens(actual.ast).map((t) =>

scripts/update-fixtures-document-fragment.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ for (const name of TARGETS) {
5858
path.join(ROOT, `${name}/parser-options.js`),
5959
].find((fp) => fs.existsSync(fp))
6060
const source = fs.readFileSync(sourcePath, "utf8")
61-
const options = Object.assign(
62-
{ filePath: sourcePath },
63-
PARSER_OPTIONS,
64-
optionsPath ? require(optionsPath) : {},
65-
)
61+
const options = {
62+
filePath: sourcePath,
63+
...PARSER_OPTIONS,
64+
...(optionsPath ? require(optionsPath) : {}),
65+
}
66+
6667
const result = parser.parseForESLint(source, options)
6768
const actual = result.services.getDocumentFragment()
6869

src/ast/traverse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const KEYS = Evk.unionWith({
2727
VSlotScopeExpression: ["params"],
2828
VStartTag: ["attributes"],
2929
VText: [],
30+
VGenericExpression: ["expression"],
3031
})
3132

3233
/**
@@ -82,7 +83,7 @@ function traverse(node: Node, parent: Node | null, visitor: Visitor): void {
8283
visitor.enterNode(node, parent)
8384

8485
const keys =
85-
(visitor.visitorKeys || KEYS)[node.type] || getFallbackKeys(node)
86+
(visitor.visitorKeys ?? KEYS)[node.type] ?? getFallbackKeys(node)
8687
for (i = 0; i < keys.length; ++i) {
8788
const child = (node as any)[keys[i]]
8889

src/common/ast-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export function isLang(
7878
* @returns The `lang` attribute value.
7979
*/
8080
export function getLang(element: VElement | undefined): string | null {
81-
const langAttr = element && element.startTag.attributes.find(isLang)
82-
const lang = langAttr && langAttr.value && langAttr.value.value
81+
const langAttr = element?.startTag.attributes.find(isLang)
82+
const lang = langAttr?.value?.value
8383
return lang || null
8484
}
8585
/**

src/common/eslint-scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let escopeCache: ESLintScope | null = null
1212
* Load the newest `eslint-scope` from the loaded ESLint or dependency.
1313
*/
1414
export function getEslintScope(): ESLintScope {
15-
return escopeCache || (escopeCache = getNewest())
15+
return escopeCache ?? (escopeCache = getNewest())
1616
}
1717

1818
/**

src/common/espree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let espreeCache: Espree | null = null
1616
* Gets the espree that the given ecmaVersion can parse.
1717
*/
1818
export function getEspree(): Espree {
19-
return espreeCache || (espreeCache = getNewestEspree())
19+
return espreeCache ?? (espreeCache = getNewestEspree())
2020
}
2121

2222
export function getEcmaVersionIfUseEspree(

src/common/fix-locations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export function fixLocations(
2424
): void {
2525
fixNodeLocations(result.ast, result.visitorKeys, locationCalculator)
2626

27-
for (const token of result.ast.tokens || []) {
27+
for (const token of result.ast.tokens ?? []) {
2828
fixLocation(token, locationCalculator)
2929
}
30-
for (const comment of result.ast.comments || []) {
30+
for (const comment of result.ast.comments ?? []) {
3131
fixLocation(comment, locationCalculator)
3232
}
3333
}

src/common/location-calculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class LocationCalculatorForHtml
6262
super(ltOffsets)
6363
this.gapOffsets = gapOffsets
6464
this.ltOffsets = ltOffsets
65-
this.baseOffset = baseOffset || 0
65+
this.baseOffset = baseOffset ?? 0
6666
this.baseIndexOfGap =
6767
this.baseOffset === 0
6868
? 0

src/external/token-store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export default class TokenStore {
334334
)
335335
.getOneToken()
336336

337-
if (token && token.range[0] === offset) {
337+
if (token?.range[0] === offset) {
338338
return token
339339
}
340340
return null

src/html/intermediate-tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class IntermediateTokenizer {
222222
private processComment(token: Token): IntermediateToken | null {
223223
this.comments.push(token)
224224

225-
if (this.currentToken != null && this.currentToken.type === "Text") {
225+
if (this.currentToken?.type === "Text") {
226226
return this.commit()
227227
}
228228
return null

0 commit comments

Comments
 (0)