@embroider/macros 1.21.0 → 1.21.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/README.md +24 -0
- package/package.json +2 -4
- package/src/babel/app-ember-satisfies.d.ts +0 -5
- package/src/babel/app-ember-satisfies.js +0 -38
- package/src/babel/app-ember-satisfies.js.map +0 -1
- package/src/babel/dependency-satisfies.d.ts +0 -5
- package/src/babel/dependency-satisfies.js +0 -38
- package/src/babel/dependency-satisfies.js.map +0 -1
- package/src/babel/each.d.ts +0 -14
- package/src/babel/each.js +0 -55
- package/src/babel/each.js.map +0 -1
- package/src/babel/error.d.ts +0 -3
- package/src/babel/error.js +0 -21
- package/src/babel/error.js.map +0 -1
- package/src/babel/evaluate-json.d.ts +0 -36
- package/src/babel/evaluate-json.js +0 -429
- package/src/babel/evaluate-json.js.map +0 -1
- package/src/babel/fail-build.d.ts +0 -5
- package/src/babel/fail-build.js +0 -36
- package/src/babel/fail-build.js.map +0 -1
- package/src/babel/get-config.d.ts +0 -9
- package/src/babel/get-config.js +0 -107
- package/src/babel/get-config.js.map +0 -1
- package/src/babel/import-sync-pattern.d.ts +0 -22
- package/src/babel/import-sync-pattern.js +0 -151
- package/src/babel/import-sync-pattern.js.map +0 -1
- package/src/babel/macro-condition.d.ts +0 -12
- package/src/babel/macro-condition.js +0 -76
- package/src/babel/macro-condition.js.map +0 -1
- package/src/babel/macros-babel-plugin.d.ts +0 -3
- package/src/babel/macros-babel-plugin.js +0 -312
- package/src/babel/macros-babel-plugin.js.map +0 -1
- package/src/babel/module-exists.d.ts +0 -5
- package/src/babel/module-exists.js +0 -30
- package/src/babel/module-exists.js.map +0 -1
- package/src/babel/state.d.ts +0 -34
- package/src/babel/state.js +0 -64
- package/src/babel/state.js.map +0 -1
- package/src/babel.d.ts +0 -47
- package/src/babel.js +0 -36
- package/src/babel.js.map +0 -1
- package/src/ember-addon-main.d.ts +0 -9
- package/src/ember-addon-main.js +0 -112
- package/src/ember-addon-main.js.map +0 -1
- package/src/glimmer/app-ember-satisfies.d.ts +0 -3
- package/src/glimmer/app-ember-satisfies.js +0 -32
- package/src/glimmer/app-ember-satisfies.js.map +0 -1
- package/src/glimmer/ast-transform.d.ts +0 -133
- package/src/glimmer/ast-transform.js +0 -240
- package/src/glimmer/ast-transform.js.map +0 -1
- package/src/glimmer/dependency-satisfies.d.ts +0 -3
- package/src/glimmer/dependency-satisfies.js +0 -37
- package/src/glimmer/dependency-satisfies.js.map +0 -1
- package/src/glimmer/evaluate.d.ts +0 -7
- package/src/glimmer/evaluate.js +0 -16
- package/src/glimmer/evaluate.js.map +0 -1
- package/src/glimmer/fail-build.d.ts +0 -2
- package/src/glimmer/fail-build.js +0 -22
- package/src/glimmer/fail-build.js.map +0 -1
- package/src/glimmer/get-config.d.ts +0 -5
- package/src/glimmer/get-config.js +0 -38
- package/src/glimmer/get-config.js.map +0 -1
- package/src/glimmer/literal.d.ts +0 -2
- package/src/glimmer/literal.js +0 -28
- package/src/glimmer/literal.js.map +0 -1
- package/src/glimmer/macro-condition.d.ts +0 -7
- package/src/glimmer/macro-condition.js +0 -119
- package/src/glimmer/macro-condition.js.map +0 -1
- package/src/glimmer/macro-maybe-attrs.d.ts +0 -2
- package/src/glimmer/macro-maybe-attrs.js +0 -31
- package/src/glimmer/macro-maybe-attrs.js.map +0 -1
- package/src/index.d.ts +0 -59
- package/src/index.js +0 -80
- package/src/index.js.map +0 -1
- package/src/macros-config.d.ts +0 -52
- package/src/macros-config.js +0 -394
- package/src/macros-config.js.map +0 -1
- package/src/node.d.ts +0 -5
- package/src/node.js +0 -21
- package/src/node.js.map +0 -1
package/README.md
CHANGED
|
@@ -222,6 +222,30 @@ if (macroCondition(dependencySatisfies('ember-qunit', '*'))) {
|
|
|
222
222
|
{{macroDependencySatisfies 'qunit' '^2.8.0'}}
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
### appEmberSatisfies
|
|
226
|
+
|
|
227
|
+
Added in `@embroider/macros` 1.19.0.
|
|
228
|
+
|
|
229
|
+
Tests whether the app's version of `ember-source` satisfies the given semver range. The argument must be a string in the syntax of [semver's satisfies](https://github.com/npm/node-semver#usage) method.
|
|
230
|
+
|
|
231
|
+
The macro always reads `ember-source` from the app, not from the package that contains the call. An addon can use it without a peer dependency on `ember-source`.
|
|
232
|
+
|
|
233
|
+
If the app does not depend on `ember-source`, the result is `false`. Prerelease versions also match, so `6.1.0-beta.1` satisfies `>= 6.0.0`.
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
import { macroCondition, appEmberSatisfies } from '@embroider/macros';
|
|
237
|
+
|
|
238
|
+
if (macroCondition(appEmberSatisfies('>= 6.0.0'))) {
|
|
239
|
+
// code for ember-source 6 and later
|
|
240
|
+
} else {
|
|
241
|
+
// code for older versions of ember-source
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```hbs
|
|
246
|
+
{{macroAppEmberSatisfies '>= 6.0.0'}}
|
|
247
|
+
```
|
|
248
|
+
|
|
225
249
|
### getOwnConfig, getConfig, and getGlobalConfig
|
|
226
250
|
|
|
227
251
|
A common pattern is to have a set of configuration properties that you define (or a consumer defines for you) which you base certain build time conditions around. This is achieved via the `getOwnConfig`, `getConfig`, and `getGlobalConfig` macros (depending on which config you want to read).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"scenario-tester": "^3.0.1",
|
|
55
55
|
"typescript": "^5.4.5",
|
|
56
56
|
"vitest": "^3.2.4",
|
|
57
|
-
"@embroider/core": "4.6.
|
|
57
|
+
"@embroider/core": "4.6.8",
|
|
58
58
|
"@embroider/test-support": "0.36.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
@@ -69,8 +69,6 @@
|
|
|
69
69
|
"node": "12.* || 14.* || >= 16"
|
|
70
70
|
},
|
|
71
71
|
"ember-addon": {
|
|
72
|
-
"version": 2,
|
|
73
|
-
"type": "addon",
|
|
74
72
|
"main": "src/ember-addon-main.js"
|
|
75
73
|
},
|
|
76
74
|
"scripts": {
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from '@babel/traverse';
|
|
2
|
-
import type { types as t } from '@babel/core';
|
|
3
|
-
import type State from './state';
|
|
4
|
-
export default function appEmberSatisfies(path: NodePath<t.CallExpression>, state: State): boolean;
|
|
5
|
-
//# sourceMappingURL=app-ember-satisfies.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = appEmberSatisfies;
|
|
7
|
-
const semver_1 = require("semver");
|
|
8
|
-
const error_1 = __importDefault(require("./error"));
|
|
9
|
-
const evaluate_json_1 = require("./evaluate-json");
|
|
10
|
-
const CACHE = new Map();
|
|
11
|
-
function getAppEmberVersion(state) {
|
|
12
|
-
var _a, _b;
|
|
13
|
-
let appRoot = state.packageCache.appRoot;
|
|
14
|
-
if (CACHE.has(appRoot)) {
|
|
15
|
-
return CACHE.get(appRoot);
|
|
16
|
-
}
|
|
17
|
-
let app = state.packageCache.get(appRoot);
|
|
18
|
-
let version = (_b = (_a = app.dependencies.find(d => d.name === 'ember-source')) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : false;
|
|
19
|
-
CACHE.set(appRoot, version);
|
|
20
|
-
return version;
|
|
21
|
-
}
|
|
22
|
-
function appEmberSatisfies(path, state) {
|
|
23
|
-
if (path.node.arguments.length !== 1) {
|
|
24
|
-
throw (0, error_1.default)(path, `appEmberSatisfies takes exactly one argument, you passed ${path.node.arguments.length}`);
|
|
25
|
-
}
|
|
26
|
-
const [range] = path.node.arguments;
|
|
27
|
-
if (range.type !== 'StringLiteral') {
|
|
28
|
-
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the only argument to appEmberSatisfies must be a string literal`);
|
|
29
|
-
}
|
|
30
|
-
let appEmberVersion = getAppEmberVersion(state);
|
|
31
|
-
if (!appEmberVersion) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return (0, semver_1.satisfies)(appEmberVersion, range.value, {
|
|
35
|
-
includePrerelease: true,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=app-ember-satisfies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-ember-satisfies.js","sourceRoot":"","sources":["app-ember-satisfies.ts"],"names":[],"mappings":";;;;;AAsBA,oCAqBC;AAxCD,mCAAmC;AACnC,oDAA4B;AAC5B,mDAA8C;AAE9C,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEhD,SAAS,kBAAkB,CAAC,KAAY;;IACtC,IAAI,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC;IAEzC,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;IAC7B,CAAC;IAED,IAAI,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,OAAO,GAAmB,MAAA,MAAA,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,0CAAE,OAAO,mCAAI,KAAK,CAAC;IACtG,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAwB,iBAAiB,CAAC,IAAgC,EAAE,KAAY;IACtF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,4DAA4D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9G,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACpC,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACnC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,eAAe,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAEhD,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAA,kBAAS,EAAC,eAAe,EAAE,KAAK,CAAC,KAAK,EAAE;QAC7C,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nconst CACHE = new Map<string, string | false>();\n\nfunction getAppEmberVersion(state: State): string | false {\n let appRoot = state.packageCache.appRoot;\n\n if (CACHE.has(appRoot)) {\n return CACHE.get(appRoot)!;\n }\n\n let app = state.packageCache.get(appRoot);\n let version: string | false = app.dependencies.find(d => d.name === 'ember-source')?.version ?? false;\n CACHE.set(appRoot, version);\n return version;\n}\n\nexport default function appEmberSatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 1) {\n throw error(path, `appEmberSatisfies takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n const [range] = path.node.arguments;\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the only argument to appEmberSatisfies must be a string literal`\n );\n }\n\n let appEmberVersion = getAppEmberVersion(state);\n\n if (!appEmberVersion) {\n return false;\n }\n\n return satisfies(appEmberVersion, range.value, {\n includePrerelease: true,\n });\n}\n"]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from '@babel/traverse';
|
|
2
|
-
import type { types as t } from '@babel/core';
|
|
3
|
-
import type State from './state';
|
|
4
|
-
export default function dependencySatisfies(path: NodePath<t.CallExpression>, state: State): boolean;
|
|
5
|
-
//# sourceMappingURL=dependency-satisfies.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = dependencySatisfies;
|
|
7
|
-
const semver_1 = require("semver");
|
|
8
|
-
const error_1 = __importDefault(require("./error"));
|
|
9
|
-
const evaluate_json_1 = require("./evaluate-json");
|
|
10
|
-
function dependencySatisfies(path, state) {
|
|
11
|
-
if (path.node.arguments.length !== 2) {
|
|
12
|
-
throw (0, error_1.default)(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);
|
|
13
|
-
}
|
|
14
|
-
const [packageName, range] = path.node.arguments;
|
|
15
|
-
if (packageName.type !== 'StringLiteral') {
|
|
16
|
-
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the first argument to dependencySatisfies must be a string literal`);
|
|
17
|
-
}
|
|
18
|
-
if (range.type !== 'StringLiteral') {
|
|
19
|
-
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[1], `the second argument to dependencySatisfies must be a string literal`);
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
let us = state.packageCache.ownerOfFile(state.sourceFile);
|
|
23
|
-
if (!(us === null || us === void 0 ? void 0 : us.hasDependency(packageName.value))) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
let version = state.packageCache.resolve(packageName.value, us).version;
|
|
27
|
-
return (0, semver_1.satisfies)(version, range.value, {
|
|
28
|
-
includePrerelease: true,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=dependency-satisfies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAOA,sCAiCC;AArCD,mCAAmC;AACnC,oDAA4B;AAC5B,mDAA8C;AAE9C,SAAwB,mBAAmB,CAAC,IAAgC,EAAE,KAAY;IACxF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,+DAA+D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACjH,CAAC;IACD,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACjD,IAAI,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACzC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACnC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,IAAI,CAAC;QACH,IAAI,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;QACxE,OAAO,IAAA,kBAAS,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE;YACrC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YACpC,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nexport default function dependencySatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 2) {\n throw error(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);\n }\n const [packageName, range] = path.node.arguments;\n if (packageName.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the first argument to dependencySatisfies must be a string literal`\n );\n }\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[1],\n `the second argument to dependencySatisfies must be a string literal`\n );\n }\n try {\n let us = state.packageCache.ownerOfFile(state.sourceFile);\n if (!us?.hasDependency(packageName.value)) {\n return false;\n }\n\n let version = state.packageCache.resolve(packageName.value, us).version;\n return satisfies(version, range.value, {\n includePrerelease: true,\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
|
package/src/babel/each.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from '@babel/traverse';
|
|
2
|
-
import type { types as t } from '@babel/core';
|
|
3
|
-
import type State from './state';
|
|
4
|
-
import type * as Babel from '@babel/core';
|
|
5
|
-
type CallEachExpression = NodePath<t.CallExpression> & {
|
|
6
|
-
get(callee: 'callee'): NodePath<t.Identifier>;
|
|
7
|
-
};
|
|
8
|
-
export type EachPath = NodePath<t.ForOfStatement> & {
|
|
9
|
-
get(right: 'right'): CallEachExpression;
|
|
10
|
-
};
|
|
11
|
-
export declare function isEachPath(path: NodePath<t.ForOfStatement>): path is EachPath;
|
|
12
|
-
export declare function insertEach(path: EachPath, state: State, context: typeof Babel): void;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=each.d.ts.map
|
package/src/babel/each.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isEachPath = isEachPath;
|
|
7
|
-
exports.insertEach = insertEach;
|
|
8
|
-
const evaluate_json_1 = require("./evaluate-json");
|
|
9
|
-
const error_1 = __importDefault(require("./error"));
|
|
10
|
-
function isEachPath(path) {
|
|
11
|
-
let right = path.get('right');
|
|
12
|
-
if (right.isCallExpression()) {
|
|
13
|
-
let callee = right.get('callee');
|
|
14
|
-
if (callee.referencesImport('@embroider/macros', 'each')) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
function insertEach(path, state, context) {
|
|
21
|
-
let args = path.get('right').get('arguments');
|
|
22
|
-
if (args.length !== 1) {
|
|
23
|
-
throw (0, error_1.default)(path, `the each() macro accepts exactly one argument, you passed ${args.length}`);
|
|
24
|
-
}
|
|
25
|
-
let left = path.get('left');
|
|
26
|
-
if (!left.isVariableDeclaration() || left.get('declarations').length !== 1) {
|
|
27
|
-
throw (0, error_1.default)(left, `the each() macro doesn't support this syntax`);
|
|
28
|
-
}
|
|
29
|
-
let body = path.get('body');
|
|
30
|
-
let varName = left.get('declarations')[0].get('id').node.name;
|
|
31
|
-
let nameRefs = body.scope.getBinding(varName).referencePaths;
|
|
32
|
-
let [arrayPath] = args;
|
|
33
|
-
let array = new evaluate_json_1.Evaluator({ state }).evaluate(arrayPath);
|
|
34
|
-
if (!array.confident) {
|
|
35
|
-
throw (0, error_1.default)(args[0], `the argument to the each() macro must be statically known`);
|
|
36
|
-
}
|
|
37
|
-
if (state.opts.mode === 'compile-time' && !Array.isArray(array.value)) {
|
|
38
|
-
throw (0, error_1.default)(args[0], `the argument to the each() macro must be an array`);
|
|
39
|
-
}
|
|
40
|
-
if (state.opts.mode === 'run-time') {
|
|
41
|
-
let callee = path.get('right').get('callee');
|
|
42
|
-
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'each'));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
for (let element of array.value) {
|
|
46
|
-
let literalElement = (0, evaluate_json_1.buildLiterals)(element, context);
|
|
47
|
-
for (let target of nameRefs) {
|
|
48
|
-
target.replaceWith(literalElement);
|
|
49
|
-
}
|
|
50
|
-
path.insertBefore(state.cloneDeep(path.get('body').node));
|
|
51
|
-
}
|
|
52
|
-
path.remove();
|
|
53
|
-
}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MAAM,IAAI,QAAQ,EAAE,CAAC;gBAC5B,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { buildLiterals, Evaluator } from './evaluate-json';\nimport type { types as t } from '@babel/core';\nimport error from './error';\nimport type State from './state';\nimport type * as Babel from '@babel/core';\n\ntype CallEachExpression = NodePath<t.CallExpression> & {\n get(callee: 'callee'): NodePath<t.Identifier>;\n};\n\nexport type EachPath = NodePath<t.ForOfStatement> & {\n get(right: 'right'): CallEachExpression;\n};\n\nexport function isEachPath(path: NodePath<t.ForOfStatement>): path is EachPath {\n let right = path.get('right');\n if (right.isCallExpression()) {\n let callee = right.get('callee');\n if (callee.referencesImport('@embroider/macros', 'each')) {\n return true;\n }\n }\n return false;\n}\n\nexport function insertEach(path: EachPath, state: State, context: typeof Babel) {\n let args = path.get('right').get('arguments');\n if (args.length !== 1) {\n throw error(path, `the each() macro accepts exactly one argument, you passed ${args.length}`);\n }\n\n let left = path.get('left');\n if (!left.isVariableDeclaration() || left.get('declarations').length !== 1) {\n throw error(left, `the each() macro doesn't support this syntax`);\n }\n\n let body = path.get('body');\n let varName = (left.get('declarations')[0].get('id') as NodePath<t.Identifier>).node.name;\n let nameRefs = body.scope.getBinding(varName)!.referencePaths;\n\n let [arrayPath] = args;\n let array = new Evaluator({ state }).evaluate(arrayPath);\n if (!array.confident) {\n throw error(args[0], `the argument to the each() macro must be statically known`);\n }\n\n if (state.opts.mode === 'compile-time' && !Array.isArray(array.value)) {\n throw error(args[0], `the argument to the each() macro must be an array`);\n }\n\n if (state.opts.mode === 'run-time') {\n let callee = path.get('right').get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'each'));\n } else {\n for (let element of array.value) {\n let literalElement = buildLiterals(element, context);\n for (let target of nameRefs) {\n target.replaceWith(literalElement);\n }\n path.insertBefore(state.cloneDeep(path.get('body').node));\n }\n path.remove();\n }\n}\n"]}
|
package/src/babel/error.d.ts
DELETED
package/src/babel/error.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = error;
|
|
4
|
-
function error(path, message) {
|
|
5
|
-
// this typecast is to workaround an issue in @types/babel__traverse https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/67183
|
|
6
|
-
return path.buildCodeFrameError(message, MacroError);
|
|
7
|
-
}
|
|
8
|
-
class MacroError extends Error {
|
|
9
|
-
constructor(message) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.type = '@embroider/macros Error';
|
|
12
|
-
this.name = 'MacroError';
|
|
13
|
-
if (typeof Error.captureStackTrace === 'function') {
|
|
14
|
-
Error.captureStackTrace(this, this.constructor);
|
|
15
|
-
}
|
|
16
|
-
else if (!this.stack) {
|
|
17
|
-
this.stack = new Error(message).stack;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=error.js.map
|
package/src/babel/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["error.ts"],"names":[],"mappings":";;AAEA,wBAGC;AAHD,SAAwB,KAAK,CAAC,IAAc,EAAE,OAAe;IAC3D,yIAAyI;IACzI,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,UAAyC,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAW,SAAQ,KAAK;IAE5B,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFjB,SAAI,GAAG,yBAAyB,CAAC;QAG/B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAClD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QACxC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { NodePath } from '@babel/traverse';\n\nexport default function error(path: NodePath, message: string) {\n // this typecast is to workaround an issue in @types/babel__traverse https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/67183\n return path.buildCodeFrameError(message, MacroError as unknown as ErrorConstructor);\n}\n\nclass MacroError extends Error {\n type = '@embroider/macros Error';\n constructor(message: string) {\n super(message);\n this.name = 'MacroError';\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(this, this.constructor);\n } else if (!this.stack) {\n this.stack = new Error(message).stack;\n }\n }\n}\n"]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from '@babel/traverse';
|
|
2
|
-
import type * as Babel from '@babel/core';
|
|
3
|
-
import type { types as t } from '@babel/core';
|
|
4
|
-
import type State from './state';
|
|
5
|
-
export interface ConfidentResult {
|
|
6
|
-
confident: true;
|
|
7
|
-
value: any;
|
|
8
|
-
hasRuntimeImplementation: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface UnknownResult {
|
|
11
|
-
confident: false;
|
|
12
|
-
}
|
|
13
|
-
export type EvaluateResult = ConfidentResult | UnknownResult;
|
|
14
|
-
export interface EvaluationEnv {
|
|
15
|
-
knownPaths?: Map<NodePath, EvaluateResult>;
|
|
16
|
-
locals?: {
|
|
17
|
-
[localVar: string]: any;
|
|
18
|
-
};
|
|
19
|
-
state?: State;
|
|
20
|
-
}
|
|
21
|
-
export declare class Evaluator {
|
|
22
|
-
private knownPaths;
|
|
23
|
-
private locals;
|
|
24
|
-
private state;
|
|
25
|
-
constructor(env?: EvaluationEnv);
|
|
26
|
-
evaluateMember(path: NodePath<t.MemberExpression | t.OptionalMemberExpression>, optionalChain: boolean): EvaluateResult;
|
|
27
|
-
evaluateKey(path: NodePath): EvaluateResult;
|
|
28
|
-
evaluate(path: NodePath): EvaluateResult;
|
|
29
|
-
private realEvaluate;
|
|
30
|
-
private maybeEvaluateRuntimeConfig;
|
|
31
|
-
evaluateMacroCall(path: NodePath<t.CallExpression>): EvaluateResult;
|
|
32
|
-
}
|
|
33
|
-
export declare function assertNotArray<T>(input: T | T[]): T;
|
|
34
|
-
export declare function assertArray<T>(input: T | T[]): T[];
|
|
35
|
-
export declare function buildLiterals(value: unknown | undefined, babelContext: typeof Babel): t.Identifier | t.ObjectExpression;
|
|
36
|
-
//# sourceMappingURL=evaluate-json.d.ts.map
|