@wyw-in-js/transform 0.1.1 → 0.2.0
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/esm/index.js +4 -1
- package/esm/index.js.map +1 -1
- package/esm/options/loadBabelOptions.js +1 -1
- package/esm/options/loadBabelOptions.js.map +1 -1
- package/esm/plugins/babel-transform.js +2 -2
- package/esm/plugins/babel-transform.js.map +1 -1
- package/esm/plugins/collector.js +4 -4
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/preeval.js +11 -11
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/plugins/shaker.js +5 -5
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +2 -2
- package/esm/shaker.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +1 -2
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +4 -4
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/generators/collect.js +3 -2
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/evalFile.js +6 -6
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +18 -14
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/transform.js +2 -2
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +3 -3
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +5 -5
- package/esm/transform/helpers/loadWywOptions.js.map +1 -0
- package/esm/transform.js +11 -10
- package/esm/transform.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +1 -1
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +10 -10
- package/esm/utils/addIdentifierToWywPreval.js.map +1 -0
- package/esm/utils/collectExportsAndImports.js +141 -53
- package/esm/utils/collectExportsAndImports.js.map +1 -1
- package/esm/utils/collectTemplateDependencies.js +2 -2
- package/esm/utils/collectTemplateDependencies.js.map +1 -1
- package/esm/utils/getTagProcessor.js +1 -1
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/esm/utils/hasWywPreval.js +7 -0
- package/esm/utils/hasWywPreval.js.map +1 -0
- package/lib/index.js +28 -4
- package/lib/index.js.map +1 -1
- package/lib/options/loadBabelOptions.js +1 -1
- package/lib/options/loadBabelOptions.js.map +1 -1
- package/lib/plugins/babel-transform.js +2 -2
- package/lib/plugins/babel-transform.js.map +1 -1
- package/lib/plugins/collector.js +4 -4
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/preeval.js +11 -11
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/plugins/shaker.js +5 -5
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +2 -2
- package/lib/shaker.js.map +1 -1
- package/lib/transform/Entrypoint.helpers.js +1 -2
- package/lib/transform/Entrypoint.helpers.js.map +1 -1
- package/lib/transform/Entrypoint.js +4 -4
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/generators/collect.js +1 -1
- package/lib/transform/generators/collect.js.map +1 -1
- package/lib/transform/generators/evalFile.js +6 -6
- package/lib/transform/generators/evalFile.js.map +1 -1
- package/lib/transform/generators/extract.js +18 -14
- package/lib/transform/generators/extract.js.map +1 -1
- package/lib/transform/generators/transform.js +2 -2
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/generators/workflow.js +3 -3
- package/lib/transform/generators/workflow.js.map +1 -1
- package/lib/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +6 -6
- package/lib/transform/helpers/loadWywOptions.js.map +1 -0
- package/lib/transform/helpers/withDefaultServices.js +2 -2
- package/lib/transform/helpers/withDefaultServices.js.map +1 -1
- package/lib/transform.js +11 -10
- package/lib/transform.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/ShakerMetadata.js +1 -1
- package/lib/utils/ShakerMetadata.js.map +1 -1
- package/lib/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/lib/utils/addIdentifierToWywPreval.js.map +1 -0
- package/lib/utils/collectExportsAndImports.js +141 -53
- package/lib/utils/collectExportsAndImports.js.map +1 -1
- package/lib/utils/collectTemplateDependencies.js +2 -2
- package/lib/utils/collectTemplateDependencies.js.map +1 -1
- package/lib/utils/getTagProcessor.js +2 -2
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/lib/utils/hasWywPreval.js +13 -0
- package/lib/utils/hasWywPreval.js.map +1 -0
- package/lib/vm/createVmContext.js +2 -2
- package/lib/vm/createVmContext.js.map +1 -1
- package/package.json +24 -21
- package/types/index.d.ts +5 -2
- package/types/index.js +9 -3
- package/types/options/loadBabelOptions.js +1 -1
- package/types/plugins/babel-transform.js +2 -2
- package/types/plugins/collector.js +4 -4
- package/types/plugins/preeval.js +11 -11
- package/types/plugins/shaker.js +5 -5
- package/types/shaker.js +2 -2
- package/types/transform/Entrypoint.d.ts +1 -1
- package/types/transform/Entrypoint.helpers.js +3 -3
- package/types/transform/Entrypoint.js +4 -4
- package/types/transform/generators/collect.js +1 -1
- package/types/transform/generators/evalFile.js +7 -7
- package/types/transform/generators/extract.js +21 -12
- package/types/transform/generators/transform.js +2 -4
- package/types/transform/generators/workflow.js +3 -3
- package/types/transform/helpers/{loadLinariaOptions.d.ts → loadWywOptions.d.ts} +1 -1
- package/types/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +19 -19
- package/types/transform.d.ts +7 -6
- package/types/transform.js +11 -10
- package/types/types.d.ts +1 -1
- package/types/utils/ShakerMetadata.d.ts +1 -1
- package/types/utils/ShakerMetadata.js +1 -1
- package/types/utils/addIdentifierToWywPreval.d.ts +4 -0
- package/types/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/types/utils/collectExportsAndImports.js +157 -58
- package/types/utils/collectTemplateDependencies.d.ts +1 -1
- package/types/utils/collectTemplateDependencies.js +2 -2
- package/types/utils/getTagProcessor.js +2 -2
- package/types/utils/hasWywPreval.d.ts +4 -0
- package/types/utils/{hasLinariaPreval.js → hasWywPreval.js} +3 -3
- package/esm/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/esm/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/esm/utils/findPackageJSON.js +0 -26
- package/esm/utils/findPackageJSON.js.map +0 -1
- package/esm/utils/hasLinariaPreval.js +0 -7
- package/esm/utils/hasLinariaPreval.js.map +0 -1
- package/lib/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/lib/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/lib/utils/findPackageJSON.js +0 -35
- package/lib/utils/findPackageJSON.js.map +0 -1
- package/lib/utils/hasLinariaPreval.js +0 -13
- package/lib/utils/hasLinariaPreval.js.map +0 -1
- package/types/utils/addIdentifierToLinariaPreval.d.ts +0 -4
- package/types/utils/findPackageJSON.d.ts +0 -1
- package/types/utils/findPackageJSON.js +0 -56
- package/types/utils/hasLinariaPreval.d.ts +0 -4
package/esm/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["isFeatureEnabled","TransformCacheCollection","Entrypoint","asyncActionRunner","syncActionRunner","baseHandlers","asyncResolveImports","syncResolveImports","
|
|
1
|
+
{"version":3,"file":"transform.js","names":["isFeatureEnabled","loadWywOptions","TransformCacheCollection","Entrypoint","asyncActionRunner","syncActionRunner","baseHandlers","asyncResolveImports","syncResolveImports","withDefaultServices","transformSync","partialServices","originalCode","syncResolve","customHandlers","options","pluginOptions","services","features","filename","cache","entrypoint","createRoot","ignored","code","sourceMap","inputSourceMap","workflowAction","createAction","undefined","result","resolveImports","call","log","name","err","console","error","transform","asyncResolve"],"sources":["../src/transform.ts"],"sourcesContent":["/**\n * This file exposes sync and async transform functions that:\n * - parse the passed code to AST\n * - builds a dependency graph for the file\n * - shakes each dependency and removes unused code\n * - runs generated code in a sandbox\n * - collects artifacts\n * - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.\n */\n\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport type { PartialOptions } from './transform/helpers/loadWywOptions';\nimport { loadWywOptions } from './transform/helpers/loadWywOptions';\nimport { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport {\n asyncActionRunner,\n syncActionRunner,\n} from './transform/actions/actionRunner';\nimport { baseHandlers } from './transform/generators';\nimport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nimport { withDefaultServices } from './transform/helpers/withDefaultServices';\nimport type {\n Handlers,\n IResolveImportsAction,\n Services,\n} from './transform/types';\nimport type { Result } from './types';\n\ntype PartialServices = Partial<Omit<Services, 'options'>> & {\n options: Omit<Services['options'], 'pluginOptions'> & {\n pluginOptions?: PartialOptions;\n };\n};\n\ntype AllHandlers<TMode extends 'async' | 'sync'> = Handlers<TMode>;\n\nexport function transformSync(\n partialServices: PartialServices,\n originalCode: string,\n syncResolve: (what: string, importer: string, stack: string[]) => string,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Result {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = syncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports() {\n return syncResolveImports.call(this, syncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n\nexport async function transform(\n partialServices: PartialServices,\n originalCode: string,\n asyncResolve: (\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Promise<Result> {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n /*\n * This method can be run simultaneously for multiple files.\n * A shared cache is accessible for all runs, but each run has its own queue\n * to maintain the correct processing order. The cache stores the outcome\n * of tree-shaking, and if the result is already stored in the cache\n * but the \"only\" option has changed, the file will be re-processed using\n * the combined \"only\" option.\n */\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = await asyncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports(this: IResolveImportsAction) {\n return asyncResolveImports.call(this, asyncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n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CAAC;EACjD;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMmB,UAAU,GAAGlB,UAAU,CAACmB,UAAU,CACtCL,QAAQ,EACRF,OAAO,CAACI,QAAQ,EAChB,CAAC,aAAa,CAAC,EACfP,YACF,CAAC;EAED,IAAIS,UAAU,CAACE,OAAO,EAAE;IACtB,OAAO;MACLC,IAAI,EAAEZ,YAAY;MAClBa,SAAS,EAAEV,OAAO,CAACW;IACrB,CAAC;EACH;EAEA,MAAMC,cAAc,GAAGN,UAAU,CAACO,YAAY,CAAC,UAAU,EAAEC,SAAS,CAAC;EAErE,IAAI;IACF,MAAMC,MAAM,GAAG,MAAM1B,iBAAiB,CAACuB,cAAc,EAAE;MACrD,GAAGrB,YAAY;MACf,GAAGQ,cAAc;MACjBiB,cAAcA,CAAA,EAA8B;QAC1C,OAAOxB,mBAAmB,CAACyB,IAAI,CAAC,IAAI,EAAEO,YAAY,CAAC;MACrD;IACF,CAAC,CAAC;IAEFlB,UAAU,CAACY,GAAG,CAAC,aAAa,EAAEZ,UAAU,CAACa,IAAI,CAAC;IAE9C,OAAOJ,MAAM;EACf,CAAC,CAAC,OAAOK,GAAG,EAAE;IACZd,UAAU,CAACY,GAAG,CAAC,oBAAoB,EAAEE,GAAG,CAAC;IAEzC,IACEnC,gBAAgB,CAACgB,aAAa,CAACE,QAAQ,EAAE,YAAY,EAAEH,OAAO,CAACI,QAAQ,CAAC,EACxE;MACA;MACAiB,OAAO,CAACC,KAAK,CAAE,6BAA4BhB,UAAU,CAACa,IAAK,GAAE,EAAEC,GAAG,CAAC;MAEnE,OAAO;QACLX,IAAI,EAAEZ,YAAY;QAClBa,SAAS,EAAEV,OAAO,CAACW;MACrB,CAAC;IACH;IAEA,MAAMS,GAAG;EACX;AACF"}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n wywInJS?: WYWTransformMetadata;\n };\n };\n processors: BaseProcessor[];\n}\n\nexport interface ITransformFileResult {\n code: string;\n metadata: WYWTransformMetadata | null;\n}\n\nexport type Stage = 'preeval' | 'collect';\n\nexport type Result = {\n code: string;\n cssSourceMapText?: string;\n cssText?: string;\n dependencies?: string[];\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n preprocessor?: Preprocessor;\n root?: string;\n};\n\nexport type PreprocessorFn = (selector: string, cssText: string) => string;\nexport type Preprocessor = 'none' | 'stylis' | PreprocessorFn | void;\n\nexport type MissedBabelCoreTypes = {\n File: new (\n options: { filename: string },\n file: { ast: File; code: string }\n ) => { path: NodePath<Program> };\n};\n\nexport type JSONValue =\n | null\n | string\n | number\n | boolean\n | JSONObject\n | JSONArray;\n\nexport interface JSONObject {\n [x: string]: JSONValue;\n}\n\nexport type JSONArray = Array<JSONValue>;\n\nexport type Serializable = JSONValue;\n\n/**\n * CSS-related types\n */\n"],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const hasShakerMetadata = metadata => metadata !== undefined && '
|
|
1
|
+
export const hasShakerMetadata = metadata => metadata !== undefined && 'wywEvaluator' in metadata;
|
|
2
2
|
//# sourceMappingURL=ShakerMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n
|
|
1
|
+
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n wywEvaluator: IShakerMetadata;\n}\n\nexport const hasShakerMetadata = (\n metadata: object | undefined\n): metadata is IMetadata =>\n metadata !== undefined && 'wywEvaluator' in metadata;\n"],"mappings":"AAQA,OAAO,MAAMA,iBAAiB,GAC5BC,QAA4B,IAE5BA,QAAQ,KAAKC,SAAS,IAAI,cAAc,IAAID,QAAQ"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createId } from './createId';
|
|
2
2
|
import { reference } from './scopeHelpers';
|
|
3
|
-
export function
|
|
3
|
+
export function getOrAddWywPreval(scope) {
|
|
4
4
|
const rootScope = scope.getProgramParent();
|
|
5
5
|
const programPath = rootScope.path;
|
|
6
|
-
let object = programPath.getData('
|
|
6
|
+
let object = programPath.getData('__wywPreval');
|
|
7
7
|
if (object) {
|
|
8
8
|
return object;
|
|
9
9
|
}
|
|
10
10
|
if (programPath.node.sourceType === 'script') {
|
|
11
|
-
// CJS exports.
|
|
11
|
+
// CJS exports.__wywPreval = {};
|
|
12
12
|
const prevalExport = {
|
|
13
13
|
expression: {
|
|
14
14
|
type: 'AssignmentExpression',
|
|
@@ -16,7 +16,7 @@ export function getOrAddLinariaPreval(scope) {
|
|
|
16
16
|
left: {
|
|
17
17
|
computed: false,
|
|
18
18
|
object: createId('exports'),
|
|
19
|
-
property: createId('
|
|
19
|
+
property: createId('__wywPreval'),
|
|
20
20
|
type: 'MemberExpression'
|
|
21
21
|
},
|
|
22
22
|
right: {
|
|
@@ -29,11 +29,11 @@ export function getOrAddLinariaPreval(scope) {
|
|
|
29
29
|
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
30
30
|
object = inserted.get('expression.right');
|
|
31
31
|
} else {
|
|
32
|
-
// ESM export const
|
|
32
|
+
// ESM export const __wywPreval = {};
|
|
33
33
|
const prevalExport = {
|
|
34
34
|
declaration: {
|
|
35
35
|
declarations: [{
|
|
36
|
-
id: createId('
|
|
36
|
+
id: createId('__wywPreval'),
|
|
37
37
|
init: {
|
|
38
38
|
properties: [],
|
|
39
39
|
type: 'ObjectExpression'
|
|
@@ -49,12 +49,12 @@ export function getOrAddLinariaPreval(scope) {
|
|
|
49
49
|
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
50
50
|
object = inserted.get('declaration.declarations.0.init');
|
|
51
51
|
}
|
|
52
|
-
programPath.setData('
|
|
52
|
+
programPath.setData('__wywPreval', object);
|
|
53
53
|
return object;
|
|
54
54
|
}
|
|
55
|
-
export function
|
|
55
|
+
export function addIdentifierToWywPreval(scope, name) {
|
|
56
56
|
const rootScope = scope.getProgramParent();
|
|
57
|
-
const object =
|
|
57
|
+
const object = getOrAddWywPreval(rootScope);
|
|
58
58
|
const newProperty = {
|
|
59
59
|
type: 'ObjectProperty',
|
|
60
60
|
key: createId(name),
|
|
@@ -65,4 +65,4 @@ export function addIdentifierToLinariaPreval(scope, name) {
|
|
|
65
65
|
const [inserted] = object.pushContainer('properties', [newProperty]);
|
|
66
66
|
reference(inserted.get('value'));
|
|
67
67
|
}
|
|
68
|
-
//# sourceMappingURL=
|
|
68
|
+
//# sourceMappingURL=addIdentifierToWywPreval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addIdentifierToWywPreval.js","names":["createId","reference","getOrAddWywPreval","scope","rootScope","getProgramParent","programPath","path","object","getData","node","sourceType","prevalExport","expression","type","operator","left","computed","property","right","properties","inserted","pushContainer","get","declaration","declarations","id","init","kind","specifiers","setData","addIdentifierToWywPreval","name","newProperty","key","value","shorthand"],"sources":["../../src/utils/addIdentifierToWywPreval.ts"],"sourcesContent":["import type { NodePath, Scope } from '@babel/traverse';\nimport type {\n ExportNamedDeclaration,\n ExpressionStatement,\n Identifier,\n ObjectExpression,\n ObjectProperty,\n Program,\n} from '@babel/types';\n\nimport { createId } from './createId';\nimport { reference } from './scopeHelpers';\n\nexport function getOrAddWywPreval(scope: Scope): NodePath<ObjectExpression> {\n const rootScope = scope.getProgramParent();\n const programPath = rootScope.path as NodePath<Program>;\n\n let object = programPath.getData('__wywPreval');\n if (object) {\n return object;\n }\n\n if (programPath.node.sourceType === 'script') {\n // CJS exports.__wywPreval = {};\n const prevalExport: ExpressionStatement = {\n expression: {\n type: 'AssignmentExpression',\n operator: '=',\n left: {\n computed: false,\n object: createId('exports'),\n property: createId('__wywPreval'),\n type: 'MemberExpression',\n },\n right: {\n properties: [],\n type: 'ObjectExpression',\n },\n },\n type: 'ExpressionStatement',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get('expression.right') as NodePath<ObjectExpression>;\n } else {\n // ESM export const __wywPreval = {};\n const prevalExport: ExportNamedDeclaration = {\n declaration: {\n declarations: [\n {\n id: createId('__wywPreval'),\n init: {\n properties: [],\n type: 'ObjectExpression',\n },\n type: 'VariableDeclarator',\n },\n ],\n kind: 'const',\n type: 'VariableDeclaration',\n },\n specifiers: [],\n type: 'ExportNamedDeclaration',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get(\n 'declaration.declarations.0.init'\n ) as NodePath<ObjectExpression>;\n }\n\n programPath.setData('__wywPreval', object);\n return object;\n}\n\nexport function addIdentifierToWywPreval(scope: Scope, name: string) {\n const rootScope = scope.getProgramParent();\n const object = getOrAddWywPreval(rootScope);\n const newProperty: ObjectProperty = {\n type: 'ObjectProperty',\n key: createId(name),\n value: createId(name),\n computed: false,\n shorthand: false,\n };\n\n const [inserted] = object.pushContainer('properties', [newProperty]);\n reference(inserted.get('value') as NodePath<Identifier>);\n}\n"],"mappings":"AAUA,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,OAAO,SAASC,iBAAiBA,CAACC,KAAY,EAA8B;EAC1E,MAAMC,SAAS,GAAGD,KAAK,CAACE,gBAAgB,CAAC,CAAC;EAC1C,MAAMC,WAAW,GAAGF,SAAS,CAACG,IAAyB;EAEvD,IAAIC,MAAM,GAAGF,WAAW,CAACG,OAAO,CAAC,aAAa,CAAC;EAC/C,IAAID,MAAM,EAAE;IACV,OAAOA,MAAM;EACf;EAEA,IAAIF,WAAW,CAACI,IAAI,CAACC,UAAU,KAAK,QAAQ,EAAE;IAC5C;IACA,MAAMC,YAAiC,GAAG;MACxCC,UAAU,EAAE;QACVC,IAAI,EAAE,sBAAsB;QAC5BC,QAAQ,EAAE,GAAG;QACbC,IAAI,EAAE;UACJC,QAAQ,EAAE,KAAK;UACfT,MAAM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AAElC,QAAQ,CAACgC,IAAI,CAAC;IACnBG,KAAK,EAAEnC,QAAQ,CAACgC,IAAI,CAAC;IACrBf,QAAQ,EAAE,KAAK;IACfmB,SAAS,EAAE;EACb,CAAC;EAED,MAAM,CAACf,QAAQ,CAAC,GAAGb,MAAM,CAACc,aAAa,CAAC,YAAY,EAAE,CAACW,WAAW,CAAC,CAAC;EACpEhC,SAAS,CAACoB,QAAQ,CAACE,GAAG,CAAC,OAAO,CAAyB,CAAC;AAC1D"}
|
|
@@ -242,21 +242,60 @@ function getCalleeName(path) {
|
|
|
242
242
|
}
|
|
243
243
|
return undefined;
|
|
244
244
|
}
|
|
245
|
-
|
|
246
|
-
const name = getCalleeName(
|
|
245
|
+
const matchCall = (p, rules) => {
|
|
246
|
+
const name = getCalleeName(p);
|
|
247
247
|
if (name === undefined) {
|
|
248
|
-
return
|
|
248
|
+
return false;
|
|
249
249
|
}
|
|
250
|
-
|
|
250
|
+
return rules.some(([n, ...args]) => {
|
|
251
|
+
if (name !== n) return false;
|
|
252
|
+
const fnArgs = p.get('arguments');
|
|
253
|
+
if (fnArgs.length !== args.length) return false;
|
|
254
|
+
return args.every((arg, i) => {
|
|
255
|
+
if (arg === '*') return true;
|
|
256
|
+
if (typeof arg === 'function') return arg(fnArgs[i]);
|
|
257
|
+
return arg === fnArgs[i];
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
function getImportExportTypeByInteropFunction(path, argPath) {
|
|
262
|
+
if (matchCall(path, [['__exportStar', argPath, p => isExports(p)]])) {
|
|
251
263
|
return 're-export:*';
|
|
252
264
|
}
|
|
253
|
-
if (
|
|
265
|
+
if (matchCall(path, [['_interopRequireDefault', argPath],
|
|
266
|
+
// babel and swc <1.3.50
|
|
267
|
+
['_interop_require_default', argPath],
|
|
268
|
+
// swc >=1.3.50
|
|
269
|
+
['__importDefault', argPath] // ?
|
|
270
|
+
])) {
|
|
254
271
|
return 'default';
|
|
255
272
|
}
|
|
256
|
-
if (
|
|
273
|
+
if (matchCall(path, [['_interopRequireWildcard', argPath],
|
|
274
|
+
// babel and swc <1.3.50
|
|
275
|
+
['_interop_require_wildcard', argPath],
|
|
276
|
+
// swc >=1.3.50
|
|
277
|
+
['__importStar', argPath],
|
|
278
|
+
// ?
|
|
279
|
+
['__toESM', argPath],
|
|
280
|
+
// esbuild >=0.14.7
|
|
281
|
+
['__toModule', argPath] // esbuild <0.14.7
|
|
282
|
+
])) {
|
|
257
283
|
return 'import:*';
|
|
258
284
|
}
|
|
259
|
-
if (
|
|
285
|
+
if (matchCall(path, [['_extends', isEmptyObject, argPath],
|
|
286
|
+
// babel and swc
|
|
287
|
+
['__rest', argPath, isArrayExpression],
|
|
288
|
+
// tsc and esbuild <=0.11.3
|
|
289
|
+
['__objRest', argPath, isArrayExpression],
|
|
290
|
+
// esbuild >0.11.3
|
|
291
|
+
['_objectWithoutProperties', argPath, isArrayExpression],
|
|
292
|
+
// babel and swc <1.3.50
|
|
293
|
+
['_object_without_properties', argPath, isArrayExpression],
|
|
294
|
+
// swc >=1.3.50
|
|
295
|
+
['_objectDestructuringEmpty', argPath],
|
|
296
|
+
// swc <1.3.50
|
|
297
|
+
['_object_destructuring_empty', argPath] // swc >=1.3.50
|
|
298
|
+
])) {
|
|
260
299
|
return 'import:*';
|
|
261
300
|
}
|
|
262
301
|
return undefined;
|
|
@@ -270,6 +309,31 @@ function isAlreadyProcessed(path) {
|
|
|
270
309
|
}
|
|
271
310
|
return false;
|
|
272
311
|
}
|
|
312
|
+
function isRequireCall(path) {
|
|
313
|
+
return path.isCallExpression() && isRequire(path.get('callee'));
|
|
314
|
+
}
|
|
315
|
+
function isEmptyObject(path) {
|
|
316
|
+
return path.isObjectExpression() && path.node.properties.length === 0;
|
|
317
|
+
}
|
|
318
|
+
function isArrayExpression(path) {
|
|
319
|
+
return path.isArrayExpression();
|
|
320
|
+
}
|
|
321
|
+
function isCallExpression(pathOrName) {
|
|
322
|
+
if (typeof pathOrName === 'string') {
|
|
323
|
+
return p => p.isCallExpression() && p.get('callee').isIdentifier({
|
|
324
|
+
name: pathOrName
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return pathOrName.isCallExpression();
|
|
328
|
+
}
|
|
329
|
+
function isObjectExpression(path) {
|
|
330
|
+
return path.isObjectExpression();
|
|
331
|
+
}
|
|
332
|
+
function isIdentifier(name) {
|
|
333
|
+
return path => path.isIdentifier({
|
|
334
|
+
name
|
|
335
|
+
});
|
|
336
|
+
}
|
|
273
337
|
function collectFromRequire(path, state) {
|
|
274
338
|
if (!isRequire(path)) return;
|
|
275
339
|
|
|
@@ -294,10 +358,10 @@ function collectFromRequire(path, state) {
|
|
|
294
358
|
parentPath: container,
|
|
295
359
|
key
|
|
296
360
|
} = callExpression;
|
|
297
|
-
if (container.isCallExpression()
|
|
361
|
+
if (container.isCallExpression()) {
|
|
298
362
|
// It may be transpiled import such as
|
|
299
363
|
// `var _atomic = _interopRequireDefault(require("@linaria/atomic"));`
|
|
300
|
-
const imported = getImportExportTypeByInteropFunction(container);
|
|
364
|
+
const imported = getImportExportTypeByInteropFunction(container, callExpression);
|
|
301
365
|
if (!imported) {
|
|
302
366
|
// It's not a transpiled import.
|
|
303
367
|
// TODO: Can we guess that it's a namespace import?
|
|
@@ -553,10 +617,7 @@ function collectFromExports(path, state) {
|
|
|
553
617
|
// It is `exports.foo = void 0`
|
|
554
618
|
return;
|
|
555
619
|
}
|
|
556
|
-
|
|
557
|
-
name
|
|
558
|
-
} = property.node;
|
|
559
|
-
if (name === '__esModule') {
|
|
620
|
+
if (exportName === '__esModule') {
|
|
560
621
|
// eslint-disable-next-line no-param-reassign
|
|
561
622
|
state.isEsModule = true;
|
|
562
623
|
return;
|
|
@@ -623,7 +684,10 @@ function unfoldNamespaceImport(importItem) {
|
|
|
623
684
|
if (!binding?.referenced) {
|
|
624
685
|
// Imported namespace is not referenced and probably not used,
|
|
625
686
|
// but it can have side effects, so we should keep it as is
|
|
626
|
-
return [
|
|
687
|
+
return [{
|
|
688
|
+
...importItem,
|
|
689
|
+
imported: 'side-effect'
|
|
690
|
+
}];
|
|
627
691
|
}
|
|
628
692
|
for (const referencePath of binding?.referencePaths ?? []) {
|
|
629
693
|
if (referencePath.find(ancestor => ancestor.isTSType() || ancestor.isFlowType())) {
|
|
@@ -665,7 +729,7 @@ function unfoldNamespaceImport(importItem) {
|
|
|
665
729
|
}
|
|
666
730
|
if (parentPath?.isCallExpression() && referencePath.listKey === 'arguments') {
|
|
667
731
|
// The defined variable is used as a function argument. Let's try to figure out what is imported.
|
|
668
|
-
const importType = getImportExportTypeByInteropFunction(parentPath);
|
|
732
|
+
const importType = getImportExportTypeByInteropFunction(parentPath, referencePath);
|
|
669
733
|
if (!importType) {
|
|
670
734
|
// Imported value is used as an unknown function argument,
|
|
671
735
|
// so we can't predict usage and import it as is.
|
|
@@ -808,8 +872,10 @@ function collectFromAssignmentExpression(path, state) {
|
|
|
808
872
|
let exported;
|
|
809
873
|
if (left.isMemberExpression() && isExports(left.get('object'))) {
|
|
810
874
|
const property = left.get('property');
|
|
811
|
-
if (property.isIdentifier()) {
|
|
875
|
+
if (!left.node.computed && property.isIdentifier()) {
|
|
812
876
|
exported = property.node.name;
|
|
877
|
+
} else if (left.node.computed && property.isStringLiteral()) {
|
|
878
|
+
exported = property.node.value;
|
|
813
879
|
}
|
|
814
880
|
} else if (isExports(left)) {
|
|
815
881
|
// module.exports = ...
|
|
@@ -818,9 +884,23 @@ function collectFromAssignmentExpression(path, state) {
|
|
|
818
884
|
}
|
|
819
885
|
}
|
|
820
886
|
if (!exported) return;
|
|
821
|
-
if (
|
|
887
|
+
if (exported === '__esModule') {
|
|
822
888
|
// eslint-disable-next-line no-param-reassign
|
|
823
|
-
state.
|
|
889
|
+
state.isEsModule = true;
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
if (!isRequireCall(right)) {
|
|
893
|
+
const relatedImport = state.imports.find(imp => imp.local === right);
|
|
894
|
+
if (relatedImport) {
|
|
895
|
+
state.reexports.push({
|
|
896
|
+
exported,
|
|
897
|
+
...relatedImport
|
|
898
|
+
});
|
|
899
|
+
} else {
|
|
900
|
+
// eslint-disable-next-line no-param-reassign
|
|
901
|
+
state.exports[exported] = right;
|
|
902
|
+
}
|
|
903
|
+
path.skip();
|
|
824
904
|
return;
|
|
825
905
|
}
|
|
826
906
|
const sourcePath = right.get('arguments')?.[0];
|
|
@@ -841,9 +921,8 @@ function collectFromAssignmentExpression(path, state) {
|
|
|
841
921
|
});
|
|
842
922
|
path.skip();
|
|
843
923
|
}
|
|
844
|
-
function
|
|
845
|
-
const
|
|
846
|
-
if (!isExports(exports)) return;
|
|
924
|
+
function collectAllFromCall(path, require, state) {
|
|
925
|
+
const requireCall = typeof require === 'number' ? path.get('arguments')[require] : require;
|
|
847
926
|
if (!requireCall.isCallExpression()) return;
|
|
848
927
|
const callee = requireCall.get('callee');
|
|
849
928
|
const sourcePath = requireCall.get('arguments')?.[0];
|
|
@@ -873,24 +952,31 @@ function collectFromMap(map, state) {
|
|
|
873
952
|
addExport(returnValue, exported, state);
|
|
874
953
|
});
|
|
875
954
|
}
|
|
876
|
-
function
|
|
877
|
-
const
|
|
878
|
-
if (!sourceExports.isIdentifier({
|
|
879
|
-
name: 'source_exports'
|
|
880
|
-
})) return;
|
|
955
|
+
function collectMapFromCall(path, mapPosition, state) {
|
|
956
|
+
const map = path.get('arguments')[mapPosition];
|
|
881
957
|
if (!map.isObjectExpression()) return;
|
|
882
958
|
collectFromMap(map, state);
|
|
883
959
|
path.skip();
|
|
884
960
|
}
|
|
885
961
|
function collectFromEsbuildReExportCall(path, state) {
|
|
886
|
-
const [sourceExports,
|
|
962
|
+
const [sourceExports, someCall, exports] = path.get('arguments');
|
|
887
963
|
if (!sourceExports.isIdentifier({
|
|
888
964
|
name: 'source_exports'
|
|
889
|
-
})) return;
|
|
890
|
-
if (!
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
965
|
+
}) && !isExports(sourceExports)) return;
|
|
966
|
+
if (!someCall.isCallExpression()) return;
|
|
967
|
+
let requireCall = someCall;
|
|
968
|
+
while (!isRequire(requireCall.get('callee'))) {
|
|
969
|
+
const args = requireCall.get('arguments');
|
|
970
|
+
if (args.length !== 1) {
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const firstArg = args[0];
|
|
974
|
+
if (!firstArg.isCallExpression()) {
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
requireCall = firstArg;
|
|
978
|
+
}
|
|
979
|
+
if (exports !== undefined && !isExports(exports)) return;
|
|
894
980
|
const sourcePath = requireCall.get('arguments')?.[0];
|
|
895
981
|
if (!sourcePath.isStringLiteral()) return;
|
|
896
982
|
state.reexports.push({
|
|
@@ -901,41 +987,43 @@ function collectFromEsbuildReExportCall(path, state) {
|
|
|
901
987
|
});
|
|
902
988
|
path.skip();
|
|
903
989
|
}
|
|
904
|
-
function collectFromSwcExportCall(path, state) {
|
|
905
|
-
const [exports, map] = path.get('arguments');
|
|
906
|
-
if (!isExports(exports)) return;
|
|
907
|
-
if (!map.isObjectExpression()) return;
|
|
908
|
-
collectFromMap(map, state);
|
|
909
|
-
path.skip();
|
|
910
|
-
}
|
|
911
990
|
function collectFromCallExpression(path, state) {
|
|
912
991
|
const maybeExportStart = path.get('callee');
|
|
913
992
|
if (!maybeExportStart.isIdentifier()) {
|
|
914
993
|
return;
|
|
915
994
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
} = maybeExportStart.node;
|
|
995
|
+
if (matchCall(path, [['__exportStar', isExports, isCallExpression('__toModule')]])) {
|
|
996
|
+
// __exportStar(exports, __toModule(require('…')));
|
|
919
997
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
collectFromExportStarCall(path, state);
|
|
998
|
+
const secondArg = path.get('arguments')[1];
|
|
999
|
+
collectAllFromCall(path, secondArg.get('arguments')[0], state);
|
|
923
1000
|
return;
|
|
924
1001
|
}
|
|
925
1002
|
|
|
926
|
-
// swc
|
|
927
|
-
if (
|
|
928
|
-
|
|
1003
|
+
// TypeScript & swc
|
|
1004
|
+
if (matchCall(path, [['__exportStart', isRequireCall, isExports], ['_exportStar', isRequireCall, isExports], ['_export_star', isRequireCall, isExports], ['__export', isRequireCall] // TypeScript <=3.8.3
|
|
1005
|
+
])) {
|
|
1006
|
+
collectAllFromCall(path, 0, state);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (matchCall(path, [['_export', isExports, isObjectExpression]])) {
|
|
1010
|
+
collectMapFromCall(path, 1, state);
|
|
1011
|
+
return;
|
|
929
1012
|
}
|
|
930
|
-
if (
|
|
931
|
-
|
|
1013
|
+
if (matchCall(path, [['_extends', isEmptyObject, isRequireCall] // swc <=1.3.16
|
|
1014
|
+
])) {
|
|
1015
|
+
collectAllFromCall(path, 1, state);
|
|
1016
|
+
return;
|
|
932
1017
|
}
|
|
933
1018
|
|
|
934
1019
|
// esbuild
|
|
935
|
-
if (
|
|
936
|
-
|
|
1020
|
+
if (matchCall(path, [['__export', isExports, isObjectExpression], ['__export', isIdentifier('source_exports'), isObjectExpression]])) {
|
|
1021
|
+
collectMapFromCall(path, 1, state);
|
|
1022
|
+
return;
|
|
937
1023
|
}
|
|
938
|
-
if (
|
|
1024
|
+
if (matchCall(path, [
|
|
1025
|
+
// Different variants of re-exports in esbuild
|
|
1026
|
+
['__reExport', isIdentifier('source_exports'), isCallExpression, isExports], ['__reExport', isIdentifier('source_exports'), isCallExpression], ['__reExport', isExports, isCallExpression]])) {
|
|
939
1027
|
collectFromEsbuildReExportCall(path, state);
|
|
940
1028
|
}
|
|
941
1029
|
}
|