@griffel/transform 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +404 -0
- package/CHANGELOG.md +130 -0
- package/__fixtures__/assets/blank.jpg +0 -0
- package/__fixtures__/assets/code.ts +12 -0
- package/__fixtures__/assets/empty.jpg +0 -0
- package/__fixtures__/assets/output.meta.json +12 -0
- package/__fixtures__/assets/output.ts +12 -0
- package/__fixtures__/assets-multiple-declarations/blank.jpg +0 -0
- package/__fixtures__/assets-multiple-declarations/code.ts +8 -0
- package/__fixtures__/assets-multiple-declarations/empty.jpg +0 -0
- package/__fixtures__/assets-multiple-declarations/output.meta.json +9 -0
- package/__fixtures__/assets-multiple-declarations/output.ts +6 -0
- package/__fixtures__/assets-reset-styles/blank.jpg +0 -0
- package/__fixtures__/assets-reset-styles/code.ts +11 -0
- package/__fixtures__/assets-reset-styles/empty.jpg +0 -0
- package/__fixtures__/assets-reset-styles/output.meta.json +11 -0
- package/__fixtures__/assets-reset-styles/output.ts +7 -0
- package/__fixtures__/assets-urls/code.ts +13 -0
- package/__fixtures__/assets-urls/output.meta.json +14 -0
- package/__fixtures__/assets-urls/output.ts +10 -0
- package/__fixtures__/at-rules/code.ts +14 -0
- package/__fixtures__/at-rules/output.meta.json +15 -0
- package/__fixtures__/at-rules/output.ts +10 -0
- package/__fixtures__/config-classname-hash-salt/code.ts +5 -0
- package/__fixtures__/config-classname-hash-salt/output.meta.json +7 -0
- package/__fixtures__/config-classname-hash-salt/output.ts +3 -0
- package/__fixtures__/config-evaluation-rules/code.ts +8 -0
- package/__fixtures__/config-evaluation-rules/consts.ts +1 -0
- package/__fixtures__/config-evaluation-rules/output.meta.json +7 -0
- package/__fixtures__/config-evaluation-rules/output.ts +4 -0
- package/__fixtures__/config-evaluation-rules/sampleEvaluator.cjs +12 -0
- package/__fixtures__/error-argument-count/fixture.js +4 -0
- package/__fixtures__/error-cjs/fixture.js +4 -0
- package/__fixtures__/error-on-undefined/fixture.ts +7 -0
- package/__fixtures__/error-on-undefined/tokens.ts +1 -0
- package/__fixtures__/export-default/code.ts +6 -0
- package/__fixtures__/export-default/output.meta.json +14 -0
- package/__fixtures__/export-default/output.ts +6 -0
- package/__fixtures__/function-mixin/code.ts +6 -0
- package/__fixtures__/function-mixin/mixins.ts +7 -0
- package/__fixtures__/function-mixin/output.meta.json +7 -0
- package/__fixtures__/function-mixin/output.ts +4 -0
- package/__fixtures__/function-mixin/tokens.ts +3 -0
- package/__fixtures__/import-alias/code.ts +5 -0
- package/__fixtures__/import-alias/output.meta.json +7 -0
- package/__fixtures__/import-alias/output.ts +3 -0
- package/__fixtures__/import-custom-module/code.ts +6 -0
- package/__fixtures__/import-custom-module/output.meta.json +7 -0
- package/__fixtures__/import-custom-module/output.ts +4 -0
- package/__fixtures__/keyframes/code.ts +22 -0
- package/__fixtures__/keyframes/output.meta.json +17 -0
- package/__fixtures__/keyframes/output.ts +6 -0
- package/__fixtures__/multiple-declarations/code.ts +8 -0
- package/__fixtures__/multiple-declarations/output.meta.json +7 -0
- package/__fixtures__/multiple-declarations/output.ts +4 -0
- package/__fixtures__/non-existing-module-call/code.ts +10 -0
- package/__fixtures__/non-existing-module-call/module.ts +13 -0
- package/__fixtures__/non-existing-module-call/output.meta.json +7 -0
- package/__fixtures__/non-existing-module-call/output.ts +6 -0
- package/__fixtures__/object/code.ts +6 -0
- package/__fixtures__/object/output.meta.json +14 -0
- package/__fixtures__/object/output.ts +6 -0
- package/__fixtures__/object-computed-keys/code.ts +8 -0
- package/__fixtures__/object-computed-keys/output.meta.json +14 -0
- package/__fixtures__/object-computed-keys/output.ts +8 -0
- package/__fixtures__/object-imported-keys/code.ts +9 -0
- package/__fixtures__/object-imported-keys/consts.ts +2 -0
- package/__fixtures__/object-imported-keys/output.meta.json +7 -0
- package/__fixtures__/object-imported-keys/output.ts +4 -0
- package/__fixtures__/object-mixins/code.ts +11 -0
- package/__fixtures__/object-mixins/mixins.ts +17 -0
- package/__fixtures__/object-mixins/output.meta.json +16 -0
- package/__fixtures__/object-mixins/output.ts +10 -0
- package/__fixtures__/object-mixins/tokens.ts +3 -0
- package/__fixtures__/object-nesting/code.ts +13 -0
- package/__fixtures__/object-nesting/consts.ts +1 -0
- package/__fixtures__/object-nesting/output.meta.json +9 -0
- package/__fixtures__/object-nesting/output.ts +6 -0
- package/__fixtures__/object-reset/code.ts +8 -0
- package/__fixtures__/object-reset/output.meta.json +7 -0
- package/__fixtures__/object-reset/output.ts +5 -0
- package/__fixtures__/object-sequence-expr/code.ts +16 -0
- package/__fixtures__/object-sequence-expr/output.meta.json +7 -0
- package/__fixtures__/object-sequence-expr/output.ts +7 -0
- package/__fixtures__/object-shorthands/code.ts +8 -0
- package/__fixtures__/object-shorthands/output.meta.json +20 -0
- package/__fixtures__/object-shorthands/output.ts +5 -0
- package/__fixtures__/object-variables/code.ts +9 -0
- package/__fixtures__/object-variables/output.meta.json +15 -0
- package/__fixtures__/object-variables/output.ts +9 -0
- package/__fixtures__/object-variables/vars.ts +5 -0
- package/__fixtures__/reset-styles/code.ts +6 -0
- package/__fixtures__/reset-styles/output.meta.json +7 -0
- package/__fixtures__/reset-styles/output.ts +3 -0
- package/__fixtures__/reset-styles-at-rules/code.ts +7 -0
- package/__fixtures__/reset-styles-at-rules/output.meta.json +8 -0
- package/__fixtures__/reset-styles-at-rules/output.ts +3 -0
- package/__fixtures__/rules-with-metadata/code.ts +9 -0
- package/__fixtures__/rules-with-metadata/output.meta.json +14 -0
- package/__fixtures__/rules-with-metadata/output.ts +3 -0
- package/__fixtures__/shared-mixins/code.ts +7 -0
- package/__fixtures__/shared-mixins/mixins.ts +6 -0
- package/__fixtures__/shared-mixins/output.meta.json +7 -0
- package/__fixtures__/shared-mixins/output.ts +8 -0
- package/__fixtures__/static-styles/code.ts +7 -0
- package/__fixtures__/static-styles/output.meta.json +7 -0
- package/__fixtures__/static-styles/output.ts +3 -0
- package/__fixtures__/static-styles-array/code.ts +10 -0
- package/__fixtures__/static-styles-array/output.meta.json +7 -0
- package/__fixtures__/static-styles-array/output.ts +3 -0
- package/__fixtures__/static-styles-string/code.ts +3 -0
- package/__fixtures__/static-styles-string/output.meta.json +7 -0
- package/__fixtures__/static-styles-string/output.ts +3 -0
- package/__fixtures__/tokens/code.ts +11 -0
- package/__fixtures__/tokens/output.meta.json +12 -0
- package/__fixtures__/tokens/output.ts +7 -0
- package/__fixtures__/tokens/tokens.ts +4 -0
- package/__fixtures__/unsupported-css-properties/fixture.ts +16 -0
- package/__fixtures__/unsupported-css-properties/output.meta.json +5 -0
- package/__fixtures__/unsupported-css-properties/output.ts +3 -0
- package/eslint.config.mjs +31 -0
- package/package.json +7 -8
- package/project.json +51 -0
- package/src/{constants.mjs → constants.mts} +0 -1
- package/src/evaluation/astEvaluator.mts +109 -0
- package/src/evaluation/astEvaluator.test.mts +126 -0
- package/src/evaluation/batchEvaluator.mts +79 -0
- package/src/evaluation/evalCache.mts +84 -0
- package/src/evaluation/fluentTokensPlugin.mts +82 -0
- package/src/evaluation/fluentTokensPlugin.test.mts +130 -0
- package/src/evaluation/module.mts +271 -0
- package/src/evaluation/module.test.mts +133 -0
- package/src/evaluation/{process.mjs → process.mts} +12 -7
- package/src/evaluation/types.mts +49 -0
- package/src/evaluation/vmEvaluator.mts +45 -0
- package/src/evaluation/vmEvaluator.test.mts +30 -0
- package/src/{index.d.mts → index.mts} +4 -0
- package/src/transformSync.mts +425 -0
- package/src/transformSync.test.mts +429 -0
- package/src/types.mts +13 -0
- package/src/utils/convertESMtoCJS.mts +226 -0
- package/src/utils/convertESMtoCJS.test.mts +159 -0
- package/src/utils/dedupeCSSRules.mts +25 -0
- package/src/utils/dedupeCSSRules.test.mts +39 -0
- package/tsconfig.json +19 -0
- package/tsconfig.lib.json +30 -0
- package/tsconfig.spec.json +24 -0
- package/vitest.config.mts +18 -0
- package/LICENSE.md +0 -21
- package/src/constants.d.mts +0 -2
- package/src/constants.mjs.map +0 -1
- package/src/evaluation/astEvaluator.d.mts +0 -20
- package/src/evaluation/astEvaluator.mjs +0 -90
- package/src/evaluation/astEvaluator.mjs.map +0 -1
- package/src/evaluation/batchEvaluator.d.mts +0 -13
- package/src/evaluation/batchEvaluator.mjs +0 -54
- package/src/evaluation/batchEvaluator.mjs.map +0 -1
- package/src/evaluation/evalCache.d.mts +0 -9
- package/src/evaluation/evalCache.mjs +0 -65
- package/src/evaluation/evalCache.mjs.map +0 -1
- package/src/evaluation/fluentTokensPlugin.d.mts +0 -2
- package/src/evaluation/fluentTokensPlugin.mjs +0 -70
- package/src/evaluation/fluentTokensPlugin.mjs.map +0 -1
- package/src/evaluation/module.d.mts +0 -44
- package/src/evaluation/module.mjs +0 -207
- package/src/evaluation/module.mjs.map +0 -1
- package/src/evaluation/process.d.mts +0 -24
- package/src/evaluation/process.mjs.map +0 -1
- package/src/evaluation/types.d.mts +0 -34
- package/src/evaluation/types.mjs +0 -2
- package/src/evaluation/types.mjs.map +0 -1
- package/src/evaluation/vmEvaluator.d.mts +0 -3
- package/src/evaluation/vmEvaluator.mjs +0 -33
- package/src/evaluation/vmEvaluator.mjs.map +0 -1
- package/src/index.mjs +0 -9
- package/src/index.mjs.map +0 -1
- package/src/transformSync.d.mts +0 -41
- package/src/transformSync.mjs +0 -252
- package/src/transformSync.mjs.map +0 -1
- package/src/types.d.mts +0 -12
- package/src/types.mjs +0 -2
- package/src/types.mjs.map +0 -1
- package/src/utils/convertESMtoCJS.d.mts +0 -6
- package/src/utils/convertESMtoCJS.mjs +0 -203
- package/src/utils/convertESMtoCJS.mjs.map +0 -1
- package/src/utils/dedupeCSSRules.d.mts +0 -6
- package/src/utils/dedupeCSSRules.mjs +0 -19
- package/src/utils/dedupeCSSRules.mjs.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"usedProcessing": true,
|
|
3
|
+
"usedVMForEvaluation": false,
|
|
4
|
+
"cssRulesByBucket": {
|
|
5
|
+
"d": [
|
|
6
|
+
[
|
|
7
|
+
".fq3r367{border-right:5px solid red ;}",
|
|
8
|
+
{
|
|
9
|
+
"p": -1
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
".f171p8tk{border-bottom:5px solid red;}",
|
|
14
|
+
{
|
|
15
|
+
"p": -1
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { makeStyles } from '@griffel/react';
|
|
2
|
+
import { colorGreen, theme } from './vars';
|
|
3
|
+
|
|
4
|
+
const colorRed = 'red';
|
|
5
|
+
|
|
6
|
+
export const useStyles = makeStyles({
|
|
7
|
+
root: { color: colorRed, paddingLeft: '4px' },
|
|
8
|
+
icon: { color: theme.black, backgroundColor: colorGreen, marginLeft: '4px' },
|
|
9
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"usedProcessing": true,
|
|
3
|
+
"usedVMForEvaluation": true,
|
|
4
|
+
"cssRulesByBucket": {
|
|
5
|
+
"d": [
|
|
6
|
+
".fe3e8s9{color:red;}",
|
|
7
|
+
".fycuoez{padding-left:4px;}",
|
|
8
|
+
".f8wuabp{padding-right:4px;}",
|
|
9
|
+
".fusgiwz{color:#000;}",
|
|
10
|
+
".fcnqdeg{background-color:green;}",
|
|
11
|
+
".fjf1xye{margin-left:4px;}",
|
|
12
|
+
".f8zmjen{margin-right:4px;}"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __css } from '@griffel/react';
|
|
2
|
+
import { colorGreen, theme } from './vars';
|
|
3
|
+
|
|
4
|
+
const colorRed = 'red';
|
|
5
|
+
|
|
6
|
+
export const useStyles = __css({
|
|
7
|
+
root: { sj55zd: 'fe3e8s9', uwmqm3: ['fycuoez', 'f8wuabp'] },
|
|
8
|
+
icon: { sj55zd: 'fusgiwz', De3pzq: 'fcnqdeg', Frg6f3: ['fjf1xye', 'f8zmjen'] },
|
|
9
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { makeStyles } from '@griffel/react';
|
|
2
|
+
import { customTokens } from './tokens';
|
|
3
|
+
|
|
4
|
+
export const useStyles = makeStyles({
|
|
5
|
+
root: {
|
|
6
|
+
backgroundColor: 'black',
|
|
7
|
+
color: customTokens.colorPaletteBlueBorder2,
|
|
8
|
+
display: 'flex',
|
|
9
|
+
},
|
|
10
|
+
rootPrimary: { color: customTokens.colorBrandBackground },
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"usedProcessing": true,
|
|
3
|
+
"usedVMForEvaluation": true,
|
|
4
|
+
"cssRulesByBucket": {
|
|
5
|
+
"d": [
|
|
6
|
+
".f1734hy{background-color:black;}",
|
|
7
|
+
".ff34w31{color:var(--colorPaletteBlueBorder2);}",
|
|
8
|
+
".f22iagw{display:flex;}",
|
|
9
|
+
".f1817uup{color:var(--colorBrandBackground);}"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { makeStyles } from '@griffel/react';
|
|
2
|
+
|
|
3
|
+
export const useStyles = makeStyles({
|
|
4
|
+
// List of shorthand properties is not exhaustive
|
|
5
|
+
// resulting output should be empty anyway
|
|
6
|
+
root: {
|
|
7
|
+
// @ts-expect-error unsupported css properties should be stripped
|
|
8
|
+
all: 'initial',
|
|
9
|
+
// @ts-expect-error unsupported css properties should be stripped
|
|
10
|
+
borderColor: 'value',
|
|
11
|
+
// @ts-expect-error unsupported css properties should be stripped
|
|
12
|
+
borderStyle: 'value',
|
|
13
|
+
// @ts-expect-error unsupported css properties should be stripped
|
|
14
|
+
borderWidth: 'value',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import baseConfig from '../../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
ignores: ['**/dist', '**/out-tsc', '__fixtures__/*/output.ts'],
|
|
6
|
+
},
|
|
7
|
+
...baseConfig,
|
|
8
|
+
{
|
|
9
|
+
files: ['__fixtures__/*/*.ts'],
|
|
10
|
+
rules: {
|
|
11
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
12
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
files: ['vite.config.*', 'vitest.config.*'],
|
|
17
|
+
rules: {
|
|
18
|
+
'import-x/no-extraneous-dependencies': 'off',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
23
|
+
// Override or add rules here
|
|
24
|
+
rules: {},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
files: ['**/*.js', '**/*.jsx'],
|
|
28
|
+
// Override or add rules here
|
|
29
|
+
rules: {},
|
|
30
|
+
},
|
|
31
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griffel/transform",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "A package that performs build time transforms for Griffel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
"./package.json": "./package.json"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@griffel/core": "^1.
|
|
22
|
-
"@griffel/transform-shaker": "^1.0.
|
|
21
|
+
"@griffel/core": "^1.21.1",
|
|
22
|
+
"@griffel/transform-shaker": "^1.0.6",
|
|
23
23
|
"debug": "^4.3.0",
|
|
24
24
|
"magic-string": "^0.30.19",
|
|
25
|
-
"oxc-parser": "^0.
|
|
26
|
-
"oxc-walker": "^0.
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
25
|
+
"oxc-parser": "^0.132.0",
|
|
26
|
+
"oxc-walker": "^1.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@griffel/transform",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/transform/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nx/eslint:lint",
|
|
10
|
+
"outputs": ["{options.outputFile}"]
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"executor": "@nx/vitest:test",
|
|
14
|
+
"outputs": ["{options.reportsDirectory}"],
|
|
15
|
+
"options": {
|
|
16
|
+
"reportsDirectory": "{projectRoot}/../../coverage/packages/transform"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"build": {
|
|
20
|
+
"executor": "@nx/js:tsc",
|
|
21
|
+
"outputs": ["{options.outputPath}"],
|
|
22
|
+
"options": {
|
|
23
|
+
"outputPath": "dist/packages/transform",
|
|
24
|
+
"tsConfig": "packages/transform/tsconfig.lib.json",
|
|
25
|
+
"skipTypeField": true,
|
|
26
|
+
"packageJson": "packages/transform/package.json",
|
|
27
|
+
"main": "packages/transform/src/index.mts",
|
|
28
|
+
"assets": [
|
|
29
|
+
"packages/transform/README.md",
|
|
30
|
+
{
|
|
31
|
+
"glob": "LICENSE.md",
|
|
32
|
+
"input": ".",
|
|
33
|
+
"output": "."
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"type-check": {
|
|
39
|
+
"executor": "nx:run-commands",
|
|
40
|
+
"options": {
|
|
41
|
+
"cwd": "packages/transform",
|
|
42
|
+
"commands": [
|
|
43
|
+
{
|
|
44
|
+
"command": "tsc -b --pretty"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"outputs": []
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Node, ObjectExpression, Program, TemplateLiteral } from 'oxc-parser';
|
|
2
|
+
import type { EvaluationResult, AstEvaluatorContext, AstEvaluatorPlugin } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sentinel value returned by plugins and evaluateNode to signal "can't handle this node".
|
|
6
|
+
* Using a symbol avoids the cost of Error construction and stack trace capture.
|
|
7
|
+
*/
|
|
8
|
+
export const DEOPT: unique symbol = Symbol('deopt');
|
|
9
|
+
export type Deopt = typeof DEOPT;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Simple static evaluator for object expressions with nested objects.
|
|
13
|
+
* Based on Babel's evaluation approach but simplified for our specific use case.
|
|
14
|
+
*
|
|
15
|
+
* Handles:
|
|
16
|
+
* - Objects with nested objects: { root: { color: 'red', padding: 0 } }
|
|
17
|
+
* - String literals, numeric literals, boolean literals, null
|
|
18
|
+
* - Simple property access
|
|
19
|
+
*
|
|
20
|
+
* Plugins can extend evaluation to handle additional node types.
|
|
21
|
+
*/
|
|
22
|
+
export function astEvaluator(node: Node, programAst: Program, plugins: AstEvaluatorPlugin[] = []): EvaluationResult {
|
|
23
|
+
const context: AstEvaluatorContext = {
|
|
24
|
+
programAst,
|
|
25
|
+
evaluateNode,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function evaluateNode(node: Node): unknown {
|
|
29
|
+
// Base cases
|
|
30
|
+
switch (node.type) {
|
|
31
|
+
case 'Literal':
|
|
32
|
+
return node.value;
|
|
33
|
+
|
|
34
|
+
case 'ObjectExpression':
|
|
35
|
+
return evaluateObjectExpression(node);
|
|
36
|
+
|
|
37
|
+
case 'TemplateLiteral':
|
|
38
|
+
if ((node as TemplateLiteral).expressions.length === 0) {
|
|
39
|
+
return (node as TemplateLiteral).quasis[0].value.cooked;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Try plugins in order
|
|
45
|
+
// ---
|
|
46
|
+
|
|
47
|
+
for (const plugin of plugins) {
|
|
48
|
+
const result = plugin.evaluateNode(node, context);
|
|
49
|
+
|
|
50
|
+
if (result !== DEOPT) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return DEOPT;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function evaluateObjectExpression(node: ObjectExpression): unknown {
|
|
59
|
+
const obj: Record<string, unknown> = {};
|
|
60
|
+
|
|
61
|
+
for (const prop of node.properties) {
|
|
62
|
+
if (prop.type !== 'Property' || prop.kind !== 'init') {
|
|
63
|
+
return DEOPT;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let key: string;
|
|
67
|
+
|
|
68
|
+
if (prop.computed) {
|
|
69
|
+
return DEOPT;
|
|
70
|
+
} else if (prop.key.type === 'Identifier') {
|
|
71
|
+
key = prop.key.name;
|
|
72
|
+
} else if (prop.key.type === 'Literal') {
|
|
73
|
+
const keyLiteral = prop.key;
|
|
74
|
+
|
|
75
|
+
if (typeof keyLiteral.value === 'string' || typeof keyLiteral.value === 'number') {
|
|
76
|
+
key = String(keyLiteral.value);
|
|
77
|
+
} else {
|
|
78
|
+
return DEOPT;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
return DEOPT;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const value = evaluateNode(prop.value);
|
|
85
|
+
|
|
86
|
+
if (value === DEOPT) {
|
|
87
|
+
return DEOPT;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
obj[key] = value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return obj;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const result = evaluateNode(node);
|
|
97
|
+
|
|
98
|
+
if (result === DEOPT) {
|
|
99
|
+
return {
|
|
100
|
+
confident: false,
|
|
101
|
+
value: undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
confident: true,
|
|
107
|
+
value: result,
|
|
108
|
+
};
|
|
109
|
+
}
|