-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perf(ESLint): Use workers to share configuration and speed up expensi…
…ve style calculations
- Loading branch information
Showing
29 changed files
with
318 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/eslint-plugin/src/utils/extract-classnames-from-value.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const separatorRegEx = /([\t\n\f\r ]+)/ | ||
|
||
export default function extractClassnamesFromValue(classStr) { | ||
if (typeof classStr !== 'string') { | ||
return { classNames: [], whitespaces: [], headSpace: false, tailSpace: false } | ||
} | ||
const parts = classStr.split(separatorRegEx) | ||
if (parts[0] === '') { | ||
parts.shift() | ||
} | ||
if (parts[parts.length - 1] === '') { | ||
parts.pop() | ||
} | ||
const headSpace = separatorRegEx.test(parts[0]) | ||
const tailSpace = separatorRegEx.test(parts[parts.length - 1]) | ||
const isClass = (_, i) => (headSpace ? i % 2 !== 0 : i % 2 === 0) | ||
const isNotClass = (_, i) => (headSpace ? i % 2 === 0 : i % 2 !== 0) | ||
const classNames = parts.filter(isClass) | ||
const whitespaces = parts.filter(isNotClass) | ||
return { classNames: classNames, whitespaces: whitespaces, headSpace: headSpace, tailSpace: tailSpace } | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/eslint-plugin/src/utils/extract-range-from-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function extractRangeFromNode(node) { | ||
if (node.type === 'TextAttribute' && node.name === 'class') { | ||
return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset] | ||
} | ||
switch (node.value.type) { | ||
case 'JSXExpressionContainer': | ||
return node.value.expression.range | ||
default: | ||
return node.value.range | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/eslint-plugin/src/utils/extract-value-from-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
export default function extractValueFromNode(node) { | ||
if (node.type === 'TextAttribute' && node.name === 'class') { | ||
return node.value | ||
} | ||
switch (node.value.type) { | ||
case 'JSXExpressionContainer': | ||
return node.value.expression.value | ||
case 'VExpressionContainer': | ||
switch (node.value.expression.type) { | ||
case 'ArrayExpression': | ||
return node.value.expression.elements | ||
case 'ObjectExpression': | ||
return node.value.expression.properties | ||
} | ||
return node.value.expression.value | ||
default: | ||
return node.value.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
export default function findLoc(text, lines, startLine, endLine) { | ||
const targetLines = text.match(/.+(?:\r\n|\n)?/g) | ||
|
||
let checkingTargetLine = 0 | ||
let resultStart = null | ||
let checking = false | ||
|
||
for (let i = startLine; i <= endLine; i++) { | ||
const sourceCodeLine = lines[i - 1] | ||
|
||
const index = sourceCodeLine.indexOf(targetLines[checkingTargetLine].replace(/\r\n|\n/, '')) | ||
if (index !== -1) { | ||
if (checkingTargetLine === 0) { | ||
resultStart = { | ||
line: i, | ||
column: index | ||
} | ||
} | ||
if (checkingTargetLine === targetLines.length - 1) { | ||
return { | ||
start: resultStart, | ||
end: { | ||
line: i, | ||
column: index + text.length | ||
} | ||
} | ||
} | ||
checking = true | ||
checkingTargetLine++ | ||
} else { | ||
if (checking) { | ||
checking = false | ||
checkingTargetLine = 0 | ||
resultStart = null | ||
} | ||
} | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import MasterCSS, { Config, config } from '@master/css' | ||
import exploreConfig from 'explore-config' | ||
|
||
let currentCSS: MasterCSS | ||
let currentConfig: string | Config | ||
|
||
export default function getMasterCSS(config: string | Config) { | ||
if (!currentCSS || currentConfig !== config) { | ||
currentCSS = new MasterCSS(typeof config === 'object' ? config : exploreConfig(config || '')) | ||
currentConfig = config | ||
} | ||
return currentCSS | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/eslint-plugin/src/utils/get-template-element-body.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function getTemplateElementBody(text, prefix, suffix) { | ||
let arr = text.split(prefix) | ||
arr.shift() | ||
const body = arr.join(prefix) | ||
arr = body.split(suffix) | ||
arr.pop() | ||
return arr.join(suffix) | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/eslint-plugin/src/utils/get-template-element-prefix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export default function getTemplateElementPrefix(text, raw) { | ||
const idx = text.indexOf(raw) | ||
if (idx === 0) { | ||
return '' | ||
} | ||
return text.split(raw).shift() | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/eslint-plugin/src/utils/get-template-element-suffix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
export default function getTemplateElementSuffix(text, raw) { | ||
if (text.indexOf(raw) === -1) { | ||
return '' | ||
} | ||
return text.split(raw).pop() | ||
} |
Oops, something went wrong.