@embroider/compat 0.47.1 → 0.47.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/compat",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Backward compatibility layer for the Embroider build system.",
|
|
6
6
|
"repository": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
30
30
|
"@babel/preset-env": "^7.14.5",
|
|
31
31
|
"@babel/traverse": "^7.14.5",
|
|
32
|
-
"@embroider/macros": "0.47.
|
|
33
|
-
"@embroider/shared-internals": "0.47.
|
|
32
|
+
"@embroider/macros": "0.47.2",
|
|
33
|
+
"@embroider/shared-internals": "0.47.2",
|
|
34
34
|
"@types/babel__code-frame": "^7.0.2",
|
|
35
35
|
"@types/yargs": "^17.0.3",
|
|
36
36
|
"assert-never": "^1.1.0",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"typescript": "*"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"@embroider/core": "0.47.
|
|
88
|
+
"@embroider/core": "0.47.2"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": "12.* || 14.* || >= 16"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-rules.js","sourceRoot":"","sources":["dependency-rules.ts"],"names":[],"mappings":";;;AAAA,0CAAyE;AACzE,mCAAmC;AAEnC,+BAA+B;AA8J/B,6EAA6E;AAC7E,kCAAkC;AAClC,SAAgB,uBAAuB,CAAC,cAA8B;IACpE,IAAI,sBAAsB,GAAG,EAAE,CAAC;IAChC,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,IAAI,mBAAmB,GAAG,EAAE,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AAC,EAAE,KAAK,CAAC,OAAO,CAAC;gBACzD,WAAW,EAAE,KAAK,CAAC,WAAW;aAC/B,CAAC,CAAC;SACJ;KACF;IACD,IAAI,WAAW,CAAC,mBAAmB,EAAE;QACnC,KAAK,IAAI,OAAO,IAAI,WAAW,CAAC,mBAAmB,EAAE;YACnD,IAAI,KAAK,GAAG,QAAQ,CAAC,uBAAuB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACnE,KAAK,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE;gBAC1D,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAA,uBAAgB,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;aAC3F;SACF;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAxBD,8CAwBC","sourcesContent":["import { Package, explicitRelative, getOrCreate } from '@embroider/core';\nimport { satisfies } from 'semver';\nimport CompatResolver from './resolver';\nimport { dirname } from 'path';\n\nexport interface PackageRules {\n // This whole set of rules will only apply when the given addon package\n // matching the given semver range is present and active.\n package: string;\n semverRange?: string;\n\n components?: {\n // I would prefer to write the key type here as `ComponentSnippet` to aid\n // documentation, but Typescript won't allow it. See ComponentSnippet below.\n [key: string]: ComponentRules;\n };\n\n addonModules?: {\n // `filename` is relative to your package root, and it assumes v2 package\n // format. Like \"templates/components/foo.hbs\".\n [filename: string]: ModuleRules;\n };\n\n appModules?: {\n // `filename` is relative to the app's root, and it assumes v2 package\n // format. Like \"templates/components/foo.hbs\".\n [filename: string]: ModuleRules;\n };\n\n addonTemplates?: {\n // `filename` is relative to your package root, and it assumes v2 package\n // format. Like \"templates/foo.hbs\".\n [filename: string]: TemplateRules;\n };\n\n appTemplates?: {\n // `filename` is relative to the app's root, and it assumes v2 package\n // format. Like \"templates/foo.hbs\".\n [filename: string]: TemplateRules;\n };\n}\n\nexport interface ActivePackageRules extends PackageRules {\n // the location(s) of active packages that match this rule.\n roots: string[];\n}\n\nexport interface TemplateRules {\n // Tells embroider which list of components may be needed for a given path.\n // For example, if your temlate says `{{component this.panel}}` and you know\n // that `this.panel` can be either \"light-panel\" or \"dark-panel\", you would\n // say: `invokes: { \"this.panel\": [\"<LightPanel/>\", \"<DarkPanel/>\"] }`\n invokes?: {\n [path: string]: ComponentSnippet[];\n };\n}\n\nexport interface ComponentRules extends TemplateRules {\n // This declares that our component yields other components that are safe to\n // invoke with the {{component}} helper.\n //\n // The array corresponds to your yielded positional arguments. Any value that\n // is true is considered a safe component. Any value can be a hash in which\n // individual keys that are true are considered safe components.\n //\n // Examples:\n //\n // If you do: {{yield (component \"x\") }}\n // Then say: yieldsSafeComponents: [true]\n //\n // If you do: {{yield (hash x=(component \"x\") y=(component \"y\")) }}\n // Then say: yieldsSafeComponents: [{x: true, y: true}]\n //\n yieldsSafeComponents?: (boolean | { [name: string]: boolean })[];\n\n // This declares that our component yields some of its arguments unchanged.\n //\n // The array corresponds to your yielded positional arguments. Each value can\n // be:\n // false, meaning this yielded value is not one of our arguments\n // a string, meaning this yielded value is our argument with that name\n // or a POJO, whose individual properties are string naming which arguments\n // from whence they came.\n //\n // Examples:\n //\n // If you do: {{yield @foo}}\n // Then say: yieldsArguments: ['foo']\n //\n // If you do: {{yield (hash x=@foo) }}\n // Then say: yieldsArguments: [{ x: 'foo' }]\n yieldsArguments?: (string | { [name: string]: string })[];\n\n // This declares that our component accepts arguments that will be invoked\n // with the {{component}} helper. This silences warnings in the places where\n // we consume them, while introducing warnings in the places where people are\n // passing them to us (if they are doing so in a way that is too dynamic to\n // analyze).\n //\n // If you use this, you may also need to set `layout`, see below.\n acceptsComponentArguments?: ArgumentMapping[];\n\n // If you want to use `acceptsComponentArguments` on a component that\n // customies its own `layout` (which is most addon-provided components), you\n // need to tell us here how to find its template by setting either `addonPath`\n // or `appPath`.\n layout?: {\n // This is a path relative to the addon root, assuming V2 format.\n addonPath?: string;\n // This is the path relative to the app root, assuming V2 format.\n appPath?: string;\n };\n\n // An unresolvable component is usually a build error (when your app has the\n // staticComponent Option enabled). But you can tell Embroider to ignore it by\n // setting this.\n safeToIgnore?: boolean;\n}\n\nexport interface ModuleRules {\n // We will resolve these components into the corresponding JS and HBS files\n // and generate imports such that this module depends on them.\n dependsOnComponents?: ComponentSnippet[];\n\n // This adds new imports to our module, as if they were really there. Helpful\n // for working around addons that depend on things but don't say so.\n dependsOnModules?: string[];\n}\n\n// The bare \"string\" short form implies that `becomes` is the same as `name`.\nexport type ArgumentMapping =\n | string\n | {\n // the name of the argument you accept\n name: string;\n // the name its consumed as in your template\n becomes: string;\n };\n\n// A component snippet is a string containing valid HBS that is a single\n// component invocation. We use it to refer to components in a way that doesn't\n// require any new syntax or rules, and that's necessarily supported by whatever\n// build-time template resolver is in use.\n//\n// Examples of valid ComponentSnippets:\n//\n// \"{{my-component}}\"\n// \"{{my-component/foo}}\"\n// \"<MyComponent />\"\n// \"{{component 'my-component'}}\"\n//\ntype ComponentSnippet = string;\n\nexport interface PreprocessedComponentRule {\n yieldsSafeComponents: Required<ComponentRules>['yieldsSafeComponents'];\n yieldsArguments: Required<ComponentRules>['yieldsArguments'];\n dependsOnComponents: ComponentSnippet[];\n argumentsAreComponents: string[];\n safeInteriorPaths: string[];\n}\n\n// take a component rule from the authoring format to a format more optimized\n// for consumption in the resolver\nexport function preprocessComponentRule(componentRules: ComponentRules): PreprocessedComponentRule {\n let argumentsAreComponents = [];\n let safeInteriorPaths = [];\n let dependsOnComponents = [];\n if (componentRules.acceptsComponentArguments) {\n for (let entry of componentRules.acceptsComponentArguments) {\n let name, interior;\n if (typeof entry === 'string') {\n name = interior = entry;\n } else {\n name = entry.name;\n interior = entry.becomes;\n }\n if (name.startsWith('@')) {\n name = name.slice(1);\n }\n argumentsAreComponents.push(name);\n safeInteriorPaths.push(interior);\n }\n }\n if (componentRules.invokes) {\n for (let [path, snippets] of Object.entries(componentRules.invokes)) {\n safeInteriorPaths.push(path);\n for (let snippet of snippets) {\n dependsOnComponents.push(snippet);\n }\n }\n }\n return {\n argumentsAreComponents,\n safeInteriorPaths,\n dependsOnComponents,\n yieldsSafeComponents: componentRules.yieldsSafeComponents || [],\n yieldsArguments: componentRules.yieldsArguments || [],\n };\n}\n\nexport function activePackageRules(packageRules: PackageRules[], activePackages: Package[]): ActivePackageRules[] {\n // rule order implies precedence. The first rule that matches a given package\n // applies to that package, and no other rule does.\n let rootsPerRule = new Map();\n for (let pkg of activePackages) {\n for (let rule of packageRules) {\n if (rule.package === pkg.name && (!rule.semverRange || satisfies(pkg.version, rule.semverRange))) {\n let roots = getOrCreate(rootsPerRule, rule, () => []);\n roots.push(pkg.root);\n break;\n }\n }\n }\n let output = [];\n for (let [rule, roots] of rootsPerRule) {\n output.push(Object.assign({ roots }, rule));\n }\n return output;\n}\n\nexport function expandModuleRules(absPath: string, moduleRules: ModuleRules, resolver: CompatResolver) {\n let output: { absPath: string; target: string; runtimeName: string }[] = [];\n if (moduleRules.dependsOnModules) {\n for (let path of moduleRules.dependsOnModules) {\n let found = resolver.resolveImport(path, absPath);\n if (!found) {\n throw new Error(`can't locate ${path} referred to in module rules:${JSON.stringify(moduleRules, null, 2)}`);\n }\n output.push({\n absPath,\n target: explicitRelative(dirname(absPath), found.absPath),\n runtimeName: found.runtimeName,\n });\n }\n }\n if (moduleRules.dependsOnComponents) {\n for (let snippet of moduleRules.dependsOnComponents) {\n let found = resolver.resolveComponentSnippet(snippet, moduleRules);\n for (let { absPath: target, runtimeName } of found.modules) {\n output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });\n }\n }\n }\n return output;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependency-rules.js","sourceRoot":"","sources":["dependency-rules.ts"],"names":[],"mappings":";;;AAAA,0CAAyE;AACzE,mCAAmC;AAEnC,+BAA+B;AA8J/B,6EAA6E;AAC7E,kCAAkC;AAClC,SAAgB,uBAAu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E,CAAC,CAAC;aAC7G;YACD,MAAM,CAAC,IAAI,CAAC;gBACV,OAAO;gBACP,MAAM,EAAE,IAAA,uBAAgB,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC;gBACzD,WAAW,EAAE,KAAK,CAAC,WAAW;aAC/B,CAAC,CAAC;SACJ;KACF;IACD,IAAI,WAAW,CAAC,mBAAmB,EAAE;QACnC,KAAK,IAAI,OAAO,IAAI,WAAW,CAAC,mBAAmB,EAAE;YACnD,IAAI,KAAK,GAAG,QAAQ,CAAC,uBAAuB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACnE,KAAK,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE;gBAC1D,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAA,uBAAgB,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;aAC3F;SACF;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAxBD,8CAwBC","sourcesContent":["import { Package, explicitRelative, getOrCreate } from '@embroider/core';\nimport { satisfies } from 'semver';\nimport CompatResolver from './resolver';\nimport { dirname } from 'path';\n\nexport interface PackageRules {\n // This whole set of rules will only apply when the given addon package\n // matching the given semver range is present and active.\n package: string;\n semverRange?: string;\n\n components?: {\n // I would prefer to write the key type here as `ComponentSnippet` to aid\n // documentation, but Typescript won't allow it. See ComponentSnippet below.\n [key: string]: ComponentRules;\n };\n\n addonModules?: {\n // `filename` is relative to your package root, and it assumes v2 package\n // format. Like \"templates/components/foo.hbs\".\n [filename: string]: ModuleRules;\n };\n\n appModules?: {\n // `filename` is relative to the app's root, and it assumes v2 package\n // format. Like \"templates/components/foo.hbs\".\n [filename: string]: ModuleRules;\n };\n\n addonTemplates?: {\n // `filename` is relative to your package root, and it assumes v2 package\n // format. Like \"templates/foo.hbs\".\n [filename: string]: TemplateRules;\n };\n\n appTemplates?: {\n // `filename` is relative to the app's root, and it assumes v2 package\n // format. Like \"templates/foo.hbs\".\n [filename: string]: TemplateRules;\n };\n}\n\nexport interface ActivePackageRules extends PackageRules {\n // the location(s) of active packages that match this rule.\n roots: string[];\n}\n\nexport interface TemplateRules {\n // Tells embroider which list of components may be needed for a given path.\n // For example, if your template says `{{component this.panel}}` and you know\n // that `this.panel` can be either \"light-panel\" or \"dark-panel\", you would\n // say: `invokes: { \"this.panel\": [\"<LightPanel/>\", \"<DarkPanel/>\"] }`\n invokes?: {\n [path: string]: ComponentSnippet[];\n };\n}\n\nexport interface ComponentRules extends TemplateRules {\n // This declares that our component yields other components that are safe to\n // invoke with the {{component}} helper.\n //\n // The array corresponds to your yielded positional arguments. Any value that\n // is true is considered a safe component. Any value can be a hash in which\n // individual keys that are true are considered safe components.\n //\n // Examples:\n //\n // If you do: {{yield (component \"x\") }}\n // Then say: yieldsSafeComponents: [true]\n //\n // If you do: {{yield (hash x=(component \"x\") y=(component \"y\")) }}\n // Then say: yieldsSafeComponents: [{x: true, y: true}]\n //\n yieldsSafeComponents?: (boolean | { [name: string]: boolean })[];\n\n // This declares that our component yields some of its arguments unchanged.\n //\n // The array corresponds to your yielded positional arguments. Each value can\n // be:\n // false, meaning this yielded value is not one of our arguments\n // a string, meaning this yielded value is our argument with that name\n // or a POJO, whose individual properties are string naming which arguments\n // from whence they came.\n //\n // Examples:\n //\n // If you do: {{yield @foo}}\n // Then say: yieldsArguments: ['foo']\n //\n // If you do: {{yield (hash x=@foo) }}\n // Then say: yieldsArguments: [{ x: 'foo' }]\n yieldsArguments?: (string | { [name: string]: string })[];\n\n // This declares that our component accepts arguments that will be invoked\n // with the {{component}} helper. This silences warnings in the places where\n // we consume them, while introducing warnings in the places where people are\n // passing them to us (if they are doing so in a way that is too dynamic to\n // analyze).\n //\n // If you use this, you may also need to set `layout`, see below.\n acceptsComponentArguments?: ArgumentMapping[];\n\n // If you want to use `acceptsComponentArguments` on a component that\n // customies its own `layout` (which is most addon-provided components), you\n // need to tell us here how to find its template by setting either `addonPath`\n // or `appPath`.\n layout?: {\n // This is a path relative to the addon root, assuming V2 format.\n addonPath?: string;\n // This is the path relative to the app root, assuming V2 format.\n appPath?: string;\n };\n\n // An unresolvable component is usually a build error (when your app has the\n // staticComponent Option enabled). But you can tell Embroider to ignore it by\n // setting this.\n safeToIgnore?: boolean;\n}\n\nexport interface ModuleRules {\n // We will resolve these components into the corresponding JS and HBS files\n // and generate imports such that this module depends on them.\n dependsOnComponents?: ComponentSnippet[];\n\n // This adds new imports to our module, as if they were really there. Helpful\n // for working around addons that depend on things but don't say so.\n dependsOnModules?: string[];\n}\n\n// The bare \"string\" short form implies that `becomes` is the same as `name`.\nexport type ArgumentMapping =\n | string\n | {\n // the name of the argument you accept\n name: string;\n // the name its consumed as in your template\n becomes: string;\n };\n\n// A component snippet is a string containing valid HBS that is a single\n// component invocation. We use it to refer to components in a way that doesn't\n// require any new syntax or rules, and that's necessarily supported by whatever\n// build-time template resolver is in use.\n//\n// Examples of valid ComponentSnippets:\n//\n// \"{{my-component}}\"\n// \"{{my-component/foo}}\"\n// \"<MyComponent />\"\n// \"{{component 'my-component'}}\"\n//\ntype ComponentSnippet = string;\n\nexport interface PreprocessedComponentRule {\n yieldsSafeComponents: Required<ComponentRules>['yieldsSafeComponents'];\n yieldsArguments: Required<ComponentRules>['yieldsArguments'];\n dependsOnComponents: ComponentSnippet[];\n argumentsAreComponents: string[];\n safeInteriorPaths: string[];\n}\n\n// take a component rule from the authoring format to a format more optimized\n// for consumption in the resolver\nexport function preprocessComponentRule(componentRules: ComponentRules): PreprocessedComponentRule {\n let argumentsAreComponents = [];\n let safeInteriorPaths = [];\n let dependsOnComponents = [];\n if (componentRules.acceptsComponentArguments) {\n for (let entry of componentRules.acceptsComponentArguments) {\n let name, interior;\n if (typeof entry === 'string') {\n name = interior = entry;\n } else {\n name = entry.name;\n interior = entry.becomes;\n }\n if (name.startsWith('@')) {\n name = name.slice(1);\n }\n argumentsAreComponents.push(name);\n safeInteriorPaths.push(interior);\n }\n }\n if (componentRules.invokes) {\n for (let [path, snippets] of Object.entries(componentRules.invokes)) {\n safeInteriorPaths.push(path);\n for (let snippet of snippets) {\n dependsOnComponents.push(snippet);\n }\n }\n }\n return {\n argumentsAreComponents,\n safeInteriorPaths,\n dependsOnComponents,\n yieldsSafeComponents: componentRules.yieldsSafeComponents || [],\n yieldsArguments: componentRules.yieldsArguments || [],\n };\n}\n\nexport function activePackageRules(packageRules: PackageRules[], activePackages: Package[]): ActivePackageRules[] {\n // rule order implies precedence. The first rule that matches a given package\n // applies to that package, and no other rule does.\n let rootsPerRule = new Map();\n for (let pkg of activePackages) {\n for (let rule of packageRules) {\n if (rule.package === pkg.name && (!rule.semverRange || satisfies(pkg.version, rule.semverRange))) {\n let roots = getOrCreate(rootsPerRule, rule, () => []);\n roots.push(pkg.root);\n break;\n }\n }\n }\n let output = [];\n for (let [rule, roots] of rootsPerRule) {\n output.push(Object.assign({ roots }, rule));\n }\n return output;\n}\n\nexport function expandModuleRules(absPath: string, moduleRules: ModuleRules, resolver: CompatResolver) {\n let output: { absPath: string; target: string; runtimeName: string }[] = [];\n if (moduleRules.dependsOnModules) {\n for (let path of moduleRules.dependsOnModules) {\n let found = resolver.resolveImport(path, absPath);\n if (!found) {\n throw new Error(`can't locate ${path} referred to in module rules:${JSON.stringify(moduleRules, null, 2)}`);\n }\n output.push({\n absPath,\n target: explicitRelative(dirname(absPath), found.absPath),\n runtimeName: found.runtimeName,\n });\n }\n }\n if (moduleRules.dependsOnComponents) {\n for (let snippet of moduleRules.dependsOnComponents) {\n let found = resolver.resolveComponentSnippet(snippet, moduleRules);\n for (let { absPath: target, runtimeName } of found.modules) {\n output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });\n }\n }\n }\n return output;\n}\n"]}
|
|
@@ -29,6 +29,9 @@ function makeResolverTransform(resolver) {
|
|
|
29
29
|
if (scopeStack.inScope(node.path.parts[0])) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
+
if (node.path.this === true) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
32
35
|
if (node.path.parts.length > 1) {
|
|
33
36
|
// paths with a dot in them (which therefore split into more than
|
|
34
37
|
// one "part") are classically understood by ember to be contextual
|
|
@@ -81,6 +84,9 @@ function makeResolverTransform(resolver) {
|
|
|
81
84
|
if (scopeStack.inScope(node.path.parts[0])) {
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
87
|
+
if (node.path.this === true) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
84
90
|
if (node.path.parts.length > 1) {
|
|
85
91
|
// paths with a dot in them (which therefore split into more than
|
|
86
92
|
// one "part") are classically understood by ember to be contextual
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver-transform.js","sourceRoot":"","sources":["resolver-transform.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAwF;AAGxF,+EAA+E;AAC/E,qCAAqC;AACrC,SAAgB,qBAAqB,CAAC,QAAkB;IACtD,SAAS,iBAAiB,CAAC,EAAE,QAAQ,EAAwB;QAC3D,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEzB,IAAI,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;QAElC,OAAO;YACL,IAAI,EAAE,+BAA+B;YAErC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,KAAK,CAAC,IAAmB;wBACvB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBACpC,CAAC;oBACD,IAAI;wBACF,UAAU,CAAC,GAAG,EAAE,CAAC;oBACnB,CAAC;iBACF;gBACD,cAAc,CAAC,IAA0B;oBACvC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE;wBACvC,OAAO;qBACR;oBACD,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI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AO;aACR;YACD,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAuB,EAAE;gBAC3F,8CAA8C;gBAC9C,OAAO;aACR;YACD,OAAO,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;YAC5B,MAAM;QACR;YACE,OAAO,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;KAC/B;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,UAAU,CAAC,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC5E,OAAO;KACR;IAED,QAAQ,CAAC,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAEhF,OAAO;IACP,0CAA0C;IAC1C,qCAAqC;IACrC,iCAAiC;IACjC,wEAAwE;IACxE,MAAM;IACN,YAAY;IACZ,IAAI;IAEJ,OAAO;IACP,0CAA0C;IAC1C,4CAA4C;IAC5C,wCAAwC;IACxC,MAAM;IACN,sFAAsF;IACtF,YAAY;IACZ,IAAI;IAEJ,mCAAmC;IACnC,oGAAoG;IACpG,YAAY;IACZ,IAAI;IAEJ,uHAAuH;IACvH,yFAAyF;IACzF,YAAY;IACZ,IAAI;IAEJ,8FAA8F;AAChG,CAAC","sourcesContent":["import { default as Resolver, ComponentResolution, ComponentLocator } from './resolver';\nimport type { ASTv1 } from '@glimmer/syntax';\n\n// This is the AST transform that resolves components and helpers at build time\n// and puts them into `dependencies`.\nexport function makeResolverTransform(resolver: Resolver) {\n function resolverTransform({ filename }: { filename: string }) {\n resolver.enter(filename);\n\n let scopeStack = new ScopeStack();\n\n return {\n name: 'embroider-build-time-resolver',\n\n visitor: {\n Program: {\n enter(node: ASTv1.Program) {\n scopeStack.push(node.blockParams);\n },\n exit() {\n scopeStack.pop();\n },\n },\n BlockStatement(node: ASTv1.BlockStatement) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.parts.length > 1) {\n // paths with a dot in them (which therefore split into more than\n // one \"part\") are classically understood by ember to be contextual\n // components, which means there's nothing to resolve at this\n // location.\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n // a block counts as args from our perpsective (it's enough to prove\n // this thing must be a component, not content)\n let hasArgs = true;\n const resolution = resolver.resolveMustache(node.path.original, hasArgs, filename, node.path.loc);\n if (resolution && resolution.type === 'component') {\n scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {\n for (let name of argumentsAreComponents) {\n let pair = node.hash.pairs.find((pair: ASTv1.HashPair) => pair.key === name);\n if (pair) {\n handleComponentHelper(pair.value, resolver, filename, scopeStack, {\n componentName: (node.path as ASTv1.PathExpression).original,\n argumentName: name,\n });\n }\n }\n });\n }\n },\n SubExpression(node: ASTv1.SubExpression) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (node.path.this === true) {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n resolver.resolveSubExpression(node.path.original, filename, node.path.loc);\n },\n MustacheStatement(node: ASTv1.MustacheStatement) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.parts.length > 1) {\n // paths with a dot in them (which therefore split into more than\n // one \"part\") are classically understood by ember to be contextual\n // components, which means there's nothing to resolve at this\n // location.\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n let hasArgs = node.params.length > 0 || node.hash.pairs.length > 0;\n let resolution = resolver.resolveMustache(node.path.original, hasArgs, filename, node.path.loc);\n if (resolution && resolution.type === 'component') {\n for (let name of resolution.argumentsAreComponents) {\n let pair = node.hash.pairs.find((pair: ASTv1.HashPair) => pair.key === name);\n if (pair) {\n handleComponentHelper(pair.value, resolver, filename, scopeStack, {\n componentName: node.path.original,\n argumentName: name,\n });\n }\n }\n }\n },\n ElementNode: {\n enter(node: ASTv1.ElementNode) {\n if (!scopeStack.inScope(node.tag.split('.')[0])) {\n const resolution = resolver.resolveElement(node.tag, filename, node.loc);\n if (resolution && resolution.type === 'component') {\n scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {\n for (let name of argumentsAreComponents) {\n let attr = node.attributes.find((attr: ASTv1.AttrNode) => attr.name === '@' + name);\n if (attr) {\n handleComponentHelper(attr.value, resolver, filename, scopeStack, {\n componentName: node.tag,\n argumentName: name,\n });\n }\n }\n });\n }\n }\n scopeStack.push(node.blockParams);\n },\n exit() {\n scopeStack.pop();\n },\n },\n },\n };\n }\n resolverTransform.parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeResolverTransform',\n params: Resolver,\n };\n return resolverTransform;\n}\n\ninterface ComponentBlockMarker {\n type: 'componentBlockMarker';\n resolution: ComponentResolution;\n argumentsAreComponents: string[];\n exit: (marker: ComponentBlockMarker) => void;\n}\n\ntype ScopeEntry = { type: 'blockParams'; blockParams: string[] } | ComponentBlockMarker;\n\nclass ScopeStack {\n private stack: ScopeEntry[] = [];\n\n // as we enter a block, we push the block params onto here to mark them as\n // being in scope\n push(blockParams: string[]) {\n this.stack.unshift({ type: 'blockParams', blockParams });\n }\n\n // and when we leave the block they go out of scope. If this block was tagged\n // by a safe component marker, we also clear that.\n pop() {\n this.stack.shift();\n let next = this.stack[0];\n if (next && next.type === 'componentBlockMarker') {\n next.exit(next);\n this.stack.shift();\n }\n }\n\n // right before we enter a block, we might determine that some of the values\n // that will be yielded as marked (by a rule) as safe to be used with the\n // {{component}} helper.\n enteringComponentBlock(resolution: ComponentResolution, exit: ComponentBlockMarker['exit']) {\n this.stack.unshift({\n type: 'componentBlockMarker',\n resolution,\n argumentsAreComponents: resolution.argumentsAreComponents.slice(),\n exit,\n });\n }\n\n inScope(name: string) {\n for (let scope of this.stack) {\n if (scope.type === 'blockParams' && scope.blockParams.includes(name)) {\n return true;\n }\n }\n return false;\n }\n\n safeComponentInScope(name: string): boolean {\n let parts = name.split('.');\n if (parts.length > 2) {\n // we let component rules specify that they yield components or objects\n // containing components. But not deeper than that. So the max path length\n // that can refer to a marked-safe component is two segments.\n return false;\n }\n for (let i = 0; i < this.stack.length - 1; i++) {\n let here = this.stack[i];\n let next = this.stack[i + 1];\n if (here.type === 'blockParams' && next.type === 'componentBlockMarker') {\n let positionalIndex = here.blockParams.indexOf(parts[0]);\n if (positionalIndex === -1) {\n continue;\n }\n\n if (parts.length === 1) {\n if (next.resolution.yieldsComponents[positionalIndex] === true) {\n return true;\n }\n let sourceArg = next.resolution.yieldsArguments[positionalIndex];\n if (typeof sourceArg === 'string') {\n next.argumentsAreComponents.push(sourceArg);\n return true;\n }\n } else {\n let entry = next.resolution.yieldsComponents[positionalIndex];\n if (entry && typeof entry === 'object') {\n return entry[parts[1]] === true;\n }\n\n let argsEntry = next.resolution.yieldsArguments[positionalIndex];\n if (argsEntry && typeof argsEntry === 'object') {\n let sourceArg = argsEntry[parts[1]];\n if (typeof sourceArg === 'string') {\n next.argumentsAreComponents.push(sourceArg);\n return true;\n }\n }\n }\n // we found the source of the name, but there were no rules to cover it.\n // Don't keep searching higher, those are different names.\n return false;\n }\n }\n return false;\n }\n}\n\nfunction handleComponentHelper(\n param: ASTv1.Node,\n resolver: Resolver,\n moduleName: string,\n scopeStack: ScopeStack,\n impliedBecause?: { componentName: string; argumentName: string }\n): void {\n let locator: ComponentLocator;\n switch (param.type) {\n case 'StringLiteral':\n locator = { type: 'literal', path: param.value };\n break;\n case 'PathExpression':\n locator = { type: 'path', path: param.original };\n break;\n case 'MustacheStatement':\n if (param.hash.pairs.length === 0 && param.params.length === 0) {\n handleComponentHelper(param.path, resolver, moduleName, scopeStack, impliedBecause);\n return;\n } else if (param.path.type === 'PathExpression' && param.path.original === 'component') {\n // safe because we will handle this inner `{{component ...}}` mustache on its own\n return;\n } else {\n locator = { type: 'other' };\n }\n break;\n case 'TextNode':\n locator = { type: 'literal', path: param.chars };\n break;\n case 'SubExpression':\n if (param.path.type === 'PathExpression' && param.path.original === 'component') {\n // safe because we will handle this inner `(component ...)` subexpression on its own\n return;\n }\n if (param.path.type === 'PathExpression' && param.path.original === 'ensure-safe-component') {\n // safe because we trust ensure-safe-component\n return;\n }\n locator = { type: 'other' };\n break;\n default:\n locator = { type: 'other' };\n }\n\n if (locator.type === 'path' && scopeStack.safeComponentInScope(locator.path)) {\n return;\n }\n\n resolver.resolveComponentHelper(locator, moduleName, param.loc, impliedBecause);\n\n // if (\n // param.type === 'MustacheStatement' &&\n // param.hash.pairs.length === 0 &&\n // param.params.length === 0 &&\n // handleComponentHelper(param.path, resolver, moduleName, scopeStack)\n // ) {\n // return;\n // }\n\n // if (\n // param.type === 'MustacheStatement' &&\n // param.path.type === 'PathExpression' &&\n // param.path.original === 'component'\n // ) {\n // // safe because we will handle this inner `{{component ...}}` mustache on its own\n // return;\n // }\n\n // if (param.type === 'TextNode') {\n // resolver.resolveComponentHelper({ type: 'literal', path: param.chars }, moduleName, param.loc);\n // return;\n // }\n\n // if (param.type === 'SubExpression' && param.path.type === 'PathExpression' && param.path.original === 'component') {\n // // safe because we will handle this inner `(component ...)` subexpression on its own\n // return;\n // }\n\n // resolver.unresolvableComponentArgument(componentName, argumentName, moduleName, param.loc);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolver-transform.js","sourceRoot":"","sources":["resolver-transform.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAwF;AAGxF,+EAA+E;AAC/E,qCAAqC;AACrC,SAAgB,qBAAqB,CAAC,QAAkB;IACtD,SAAS,iBAAiB,CAAC,EAAE,QAAQ,EAAwB;QAC3D,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEzB,IAA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ACP,0CAA0C;IAC1C,4CAA4C;IAC5C,wCAAwC;IACxC,MAAM;IACN,sFAAsF;IACtF,YAAY;IACZ,IAAI;IAEJ,mCAAmC;IACnC,oGAAoG;IACpG,YAAY;IACZ,IAAI;IAEJ,uHAAuH;IACvH,yFAAyF;IACzF,YAAY;IACZ,IAAI;IAEJ,8FAA8F;AAChG,CAAC","sourcesContent":["import { default as Resolver, ComponentResolution, ComponentLocator } from './resolver';\nimport type { ASTv1 } from '@glimmer/syntax';\n\n// This is the AST transform that resolves components and helpers at build time\n// and puts them into `dependencies`.\nexport function makeResolverTransform(resolver: Resolver) {\n function resolverTransform({ filename }: { filename: string }) {\n resolver.enter(filename);\n\n let scopeStack = new ScopeStack();\n\n return {\n name: 'embroider-build-time-resolver',\n\n visitor: {\n Program: {\n enter(node: ASTv1.Program) {\n scopeStack.push(node.blockParams);\n },\n exit() {\n scopeStack.pop();\n },\n },\n BlockStatement(node: ASTv1.BlockStatement) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.this === true) {\n return;\n }\n if (node.path.parts.length > 1) {\n // paths with a dot in them (which therefore split into more than\n // one \"part\") are classically understood by ember to be contextual\n // components, which means there's nothing to resolve at this\n // location.\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n // a block counts as args from our perpsective (it's enough to prove\n // this thing must be a component, not content)\n let hasArgs = true;\n const resolution = resolver.resolveMustache(node.path.original, hasArgs, filename, node.path.loc);\n if (resolution && resolution.type === 'component') {\n scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {\n for (let name of argumentsAreComponents) {\n let pair = node.hash.pairs.find((pair: ASTv1.HashPair) => pair.key === name);\n if (pair) {\n handleComponentHelper(pair.value, resolver, filename, scopeStack, {\n componentName: (node.path as ASTv1.PathExpression).original,\n argumentName: name,\n });\n }\n }\n });\n }\n },\n SubExpression(node: ASTv1.SubExpression) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (node.path.this === true) {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n resolver.resolveSubExpression(node.path.original, filename, node.path.loc);\n },\n MustacheStatement(node: ASTv1.MustacheStatement) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (scopeStack.inScope(node.path.parts[0])) {\n return;\n }\n if (node.path.this === true) {\n return;\n }\n if (node.path.parts.length > 1) {\n // paths with a dot in them (which therefore split into more than\n // one \"part\") are classically understood by ember to be contextual\n // components, which means there's nothing to resolve at this\n // location.\n return;\n }\n if (node.path.original === 'component' && node.params.length > 0) {\n handleComponentHelper(node.params[0], resolver, filename, scopeStack);\n return;\n }\n let hasArgs = node.params.length > 0 || node.hash.pairs.length > 0;\n let resolution = resolver.resolveMustache(node.path.original, hasArgs, filename, node.path.loc);\n if (resolution && resolution.type === 'component') {\n for (let name of resolution.argumentsAreComponents) {\n let pair = node.hash.pairs.find((pair: ASTv1.HashPair) => pair.key === name);\n if (pair) {\n handleComponentHelper(pair.value, resolver, filename, scopeStack, {\n componentName: node.path.original,\n argumentName: name,\n });\n }\n }\n }\n },\n ElementNode: {\n enter(node: ASTv1.ElementNode) {\n if (!scopeStack.inScope(node.tag.split('.')[0])) {\n const resolution = resolver.resolveElement(node.tag, filename, node.loc);\n if (resolution && resolution.type === 'component') {\n scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {\n for (let name of argumentsAreComponents) {\n let attr = node.attributes.find((attr: ASTv1.AttrNode) => attr.name === '@' + name);\n if (attr) {\n handleComponentHelper(attr.value, resolver, filename, scopeStack, {\n componentName: node.tag,\n argumentName: name,\n });\n }\n }\n });\n }\n }\n scopeStack.push(node.blockParams);\n },\n exit() {\n scopeStack.pop();\n },\n },\n },\n };\n }\n resolverTransform.parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeResolverTransform',\n params: Resolver,\n };\n return resolverTransform;\n}\n\ninterface ComponentBlockMarker {\n type: 'componentBlockMarker';\n resolution: ComponentResolution;\n argumentsAreComponents: string[];\n exit: (marker: ComponentBlockMarker) => void;\n}\n\ntype ScopeEntry = { type: 'blockParams'; blockParams: string[] } | ComponentBlockMarker;\n\nclass ScopeStack {\n private stack: ScopeEntry[] = [];\n\n // as we enter a block, we push the block params onto here to mark them as\n // being in scope\n push(blockParams: string[]) {\n this.stack.unshift({ type: 'blockParams', blockParams });\n }\n\n // and when we leave the block they go out of scope. If this block was tagged\n // by a safe component marker, we also clear that.\n pop() {\n this.stack.shift();\n let next = this.stack[0];\n if (next && next.type === 'componentBlockMarker') {\n next.exit(next);\n this.stack.shift();\n }\n }\n\n // right before we enter a block, we might determine that some of the values\n // that will be yielded as marked (by a rule) as safe to be used with the\n // {{component}} helper.\n enteringComponentBlock(resolution: ComponentResolution, exit: ComponentBlockMarker['exit']) {\n this.stack.unshift({\n type: 'componentBlockMarker',\n resolution,\n argumentsAreComponents: resolution.argumentsAreComponents.slice(),\n exit,\n });\n }\n\n inScope(name: string) {\n for (let scope of this.stack) {\n if (scope.type === 'blockParams' && scope.blockParams.includes(name)) {\n return true;\n }\n }\n return false;\n }\n\n safeComponentInScope(name: string): boolean {\n let parts = name.split('.');\n if (parts.length > 2) {\n // we let component rules specify that they yield components or objects\n // containing components. But not deeper than that. So the max path length\n // that can refer to a marked-safe component is two segments.\n return false;\n }\n for (let i = 0; i < this.stack.length - 1; i++) {\n let here = this.stack[i];\n let next = this.stack[i + 1];\n if (here.type === 'blockParams' && next.type === 'componentBlockMarker') {\n let positionalIndex = here.blockParams.indexOf(parts[0]);\n if (positionalIndex === -1) {\n continue;\n }\n\n if (parts.length === 1) {\n if (next.resolution.yieldsComponents[positionalIndex] === true) {\n return true;\n }\n let sourceArg = next.resolution.yieldsArguments[positionalIndex];\n if (typeof sourceArg === 'string') {\n next.argumentsAreComponents.push(sourceArg);\n return true;\n }\n } else {\n let entry = next.resolution.yieldsComponents[positionalIndex];\n if (entry && typeof entry === 'object') {\n return entry[parts[1]] === true;\n }\n\n let argsEntry = next.resolution.yieldsArguments[positionalIndex];\n if (argsEntry && typeof argsEntry === 'object') {\n let sourceArg = argsEntry[parts[1]];\n if (typeof sourceArg === 'string') {\n next.argumentsAreComponents.push(sourceArg);\n return true;\n }\n }\n }\n // we found the source of the name, but there were no rules to cover it.\n // Don't keep searching higher, those are different names.\n return false;\n }\n }\n return false;\n }\n}\n\nfunction handleComponentHelper(\n param: ASTv1.Node,\n resolver: Resolver,\n moduleName: string,\n scopeStack: ScopeStack,\n impliedBecause?: { componentName: string; argumentName: string }\n): void {\n let locator: ComponentLocator;\n switch (param.type) {\n case 'StringLiteral':\n locator = { type: 'literal', path: param.value };\n break;\n case 'PathExpression':\n locator = { type: 'path', path: param.original };\n break;\n case 'MustacheStatement':\n if (param.hash.pairs.length === 0 && param.params.length === 0) {\n handleComponentHelper(param.path, resolver, moduleName, scopeStack, impliedBecause);\n return;\n } else if (param.path.type === 'PathExpression' && param.path.original === 'component') {\n // safe because we will handle this inner `{{component ...}}` mustache on its own\n return;\n } else {\n locator = { type: 'other' };\n }\n break;\n case 'TextNode':\n locator = { type: 'literal', path: param.chars };\n break;\n case 'SubExpression':\n if (param.path.type === 'PathExpression' && param.path.original === 'component') {\n // safe because we will handle this inner `(component ...)` subexpression on its own\n return;\n }\n if (param.path.type === 'PathExpression' && param.path.original === 'ensure-safe-component') {\n // safe because we trust ensure-safe-component\n return;\n }\n locator = { type: 'other' };\n break;\n default:\n locator = { type: 'other' };\n }\n\n if (locator.type === 'path' && scopeStack.safeComponentInScope(locator.path)) {\n return;\n }\n\n resolver.resolveComponentHelper(locator, moduleName, param.loc, impliedBecause);\n\n // if (\n // param.type === 'MustacheStatement' &&\n // param.hash.pairs.length === 0 &&\n // param.params.length === 0 &&\n // handleComponentHelper(param.path, resolver, moduleName, scopeStack)\n // ) {\n // return;\n // }\n\n // if (\n // param.type === 'MustacheStatement' &&\n // param.path.type === 'PathExpression' &&\n // param.path.original === 'component'\n // ) {\n // // safe because we will handle this inner `{{component ...}}` mustache on its own\n // return;\n // }\n\n // if (param.type === 'TextNode') {\n // resolver.resolveComponentHelper({ type: 'literal', path: param.chars }, moduleName, param.loc);\n // return;\n // }\n\n // if (param.type === 'SubExpression' && param.path.type === 'PathExpression' && param.path.original === 'component') {\n // // safe because we will handle this inner `(component ...)` subexpression on its own\n // return;\n // }\n\n // resolver.unresolvableComponentArgument(componentName, argumentName, moduleName, param.loc);\n}\n"]}
|