@embroider/macros 1.17.0-alpha.5 → 1.17.0-alpha.7

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/macros",
3
- "version": "1.17.0-alpha.5",
3
+ "version": "1.17.0-alpha.7",
4
4
  "private": false,
5
5
  "description": "Standardized build-time macros for ember apps.",
6
6
  "keywords": [
@@ -30,17 +30,18 @@
30
30
  "minor": "prerelease",
31
31
  "patch": "prerelease"
32
32
  },
33
- "semverIncrementTag": "alpha"
33
+ "semverIncrementTag": "alpha",
34
+ "publishTag": "alpha"
34
35
  },
35
36
  "dependencies": {
36
37
  "assert-never": "^1.2.1",
37
- "babel-import-util": "^2.0.0",
38
+ "babel-import-util": "^3.0.1",
38
39
  "ember-cli-babel": "^7.26.6",
39
40
  "find-up": "^5.0.0",
40
41
  "lodash": "^4.17.21",
41
42
  "resolve": "^1.20.0",
42
43
  "semver": "^7.3.2",
43
- "@embroider/shared-internals": "3.0.0-alpha.3"
44
+ "@embroider/shared-internals": "3.0.0-alpha.5"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@babel/core": "^7.14.5",
@@ -59,8 +60,8 @@
59
60
  "code-equality-assertions": "^1.0.1",
60
61
  "scenario-tester": "^3.0.1",
61
62
  "typescript": "^5.4.5",
62
- "@embroider/test-support": "0.36.0",
63
- "@embroider/core": "4.0.0-alpha.6"
63
+ "@embroider/core": "4.0.0-alpha.9",
64
+ "@embroider/test-support": "0.36.0"
64
65
  },
65
66
  "peerDependencies": {
66
67
  "@glint/template": "^1.0.0"
@@ -51,7 +51,7 @@ function main(context) {
51
51
  let visitor = {
52
52
  Program: {
53
53
  enter(path, state) {
54
- (0, state_1.initState)(t, path, state);
54
+ (0, state_1.initState)(context, path, state);
55
55
  },
56
56
  exit(_, state) {
57
57
  // @embroider/macros itself has no runtime behaviors and should always be removed
@@ -1 +1 @@
1
- {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,aAAa,EAAE,CAAC,YAAY,EAAE,EACpC,CAAC;gBACD,sEAAsE;gBACtE,uEAAuE;gBACvE,0DAA0D;gBAC1D,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;QACpD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;oBACvC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { initState } from './state';\nimport type { Mode as GetConfigMode } from './get-config';\nimport { inlineRuntimeConfig, insertConfig } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\nimport { existsSync, readdirSync } from 'fs';\nimport { resolve, dirname, join } from 'path';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && state.opts.mode === 'run-time') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n let relativePath = '';\n let property;\n if (specifier.type === 'TemplateLiteral') {\n relativePath = specifier.quasis[0].value.cooked!;\n property = specifier.expressions[0] as t.Expression;\n }\n // babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id)\n if (\n specifier.type === 'CallExpression' &&\n specifier.callee.type === 'MemberExpression' &&\n specifier.callee.property.type === 'Identifier' &&\n specifier.callee.property.name === 'concat' &&\n specifier.callee.object.type === 'StringLiteral'\n ) {\n relativePath = specifier.callee.object.value;\n property = specifier.arguments[0] as t.Expression;\n }\n if (property && relativePath && relativePath.startsWith('.')) {\n const resolvedPath = resolve(dirname((state as any).filename), relativePath);\n let entries: string[] = [];\n if (existsSync(resolvedPath)) {\n entries = readdirSync(resolvedPath).filter(e => !e.startsWith('.'));\n }\n const obj = t.objectExpression(\n entries.map(e => {\n let key = e.split('.')[0];\n const rest = e.split('.').slice(1, -1);\n if (rest.length) {\n key += `.${rest}`;\n }\n const id = t.callExpression(\n state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'),\n [state.importUtil.import(path, join(relativePath, key).replace(/\\\\/g, '/'), '*')]\n );\n return t.objectProperty(t.stringLiteral(key), id);\n })\n );\n const memberExpr = t.memberExpression(obj, property, true);\n path.replaceWith(memberExpr);\n state.calledIdentifiers.add(callee.node);\n return;\n } else {\n throw new Error(\n `importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier.type}`\n );\n }\n }\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n state.importUtil.import(path, specifier.value, '*'),\n ])\n );\n state.calledIdentifiers.add(callee.node);\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.hideRequires &&\n path.node.name === 'require' &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberAddon()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
1
+ {"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,uBAiPC;AA9PD,mCAAoC;AAEpC,6CAAiE;AACjE,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAE3D,2BAA6C;AAC7C,+BAA8C;AAE9C,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG;QACZ,OAAO,EAAE;YACP,KAAK,CAAC,IAAyB,EAAE,KAAY;gBAC3C,IAAA,iBAAS,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,IAAI,CAAC,CAAsB,EAAE,KAAY;gBACvC,iFAAiF;gBACjF,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,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;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { initState } from './state';\nimport type { Mode as GetConfigMode } from './get-config';\nimport { inlineRuntimeConfig, insertConfig } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\nimport { existsSync, readdirSync } from 'fs';\nimport { resolve, dirname, join } from 'path';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(context, path, state);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && state.opts.mode === 'run-time') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n let relativePath = '';\n let property;\n if (specifier.type === 'TemplateLiteral') {\n relativePath = specifier.quasis[0].value.cooked!;\n property = specifier.expressions[0] as t.Expression;\n }\n // babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id)\n if (\n specifier.type === 'CallExpression' &&\n specifier.callee.type === 'MemberExpression' &&\n specifier.callee.property.type === 'Identifier' &&\n specifier.callee.property.name === 'concat' &&\n specifier.callee.object.type === 'StringLiteral'\n ) {\n relativePath = specifier.callee.object.value;\n property = specifier.arguments[0] as t.Expression;\n }\n if (property && relativePath && relativePath.startsWith('.')) {\n const resolvedPath = resolve(dirname((state as any).filename), relativePath);\n let entries: string[] = [];\n if (existsSync(resolvedPath)) {\n entries = readdirSync(resolvedPath).filter(e => !e.startsWith('.'));\n }\n const obj = t.objectExpression(\n entries.map(e => {\n let key = e.split('.')[0];\n const rest = e.split('.').slice(1, -1);\n if (rest.length) {\n key += `.${rest}`;\n }\n const id = t.callExpression(\n state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'),\n [state.importUtil.import(path, join(relativePath, key).replace(/\\\\/g, '/'), '*')]\n );\n return t.objectProperty(t.stringLiteral(key), id);\n })\n );\n const memberExpr = t.memberExpression(obj, property, true);\n path.replaceWith(memberExpr);\n state.calledIdentifiers.add(callee.node);\n return;\n } else {\n throw new Error(\n `importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier.type}`\n );\n }\n }\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n state.importUtil.import(path, specifier.value, '*'),\n ])\n );\n state.calledIdentifiers.add(callee.node);\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.hideRequires &&\n path.node.name === 'require' &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberAddon()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
@@ -28,4 +28,4 @@ export default interface State {
28
28
  mode: 'compile-time' | 'run-time';
29
29
  };
30
30
  }
31
- export declare function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State): void;
31
+ export declare function initState(t: typeof Babel, path: NodePath<Babel.types.Program>, state: State): void;
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":";;AAiDA,8BAUC;AA1DD,+BAA8C;AAE9C,kEAAgG;AAChG,yDAA+C;AA6C/C,SAAgB,SAAS,CAAC,CAAqB,EAAE,IAAmC,EAAE,KAAY;IAChG,KAAK,CAAC,UAAU,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,YAAY,GAAG,wCAAqB,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1F,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAA,2BAAQ,EAAE,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClG,KAAK,CAAC,cAAc,GAAG,WAAW,CAAC;IACnC,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;AACtD,CAAC;AAED,MAAM,gBAAgB,GAAG,IAAA,cAAO,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAEjE,SAAS,WAAW,CAAc,UAAkB;IAClD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACjC,kEAAkE;QAClE,OAAO,IAAA,mCAAgB,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAA,WAAI,EAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC;IACxF,CAAC;SAAM,CAAC;QACN,sEAAsE;QACtE,aAAa;QACb,EAAE;QACF,qEAAqE;QACrE,yEAAyE;QACzE,4EAA4E;QAC5E,0EAA0E;QAC1E,eAAe;QACf,OAAO,qBAAqB,UAAU,EAAE,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,aAAa;IACpB,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,qBAAqB;IAC5B,IAAI,GAAG,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport { join, dirname, resolve } from 'path';\nimport type { Package } from '@embroider/shared-internals';\nimport { cleanUrl, explicitRelative, RewrittenPackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\nimport type * as Babel from '@babel/core';\n\nexport default interface State {\n importUtil: ImportUtil;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n packageCache: RewrittenPackageCache;\n sourceFile: string;\n pathToOurAddon(moduleName: string): string;\n owningPackage(): Package;\n originalOwningPackage(): Package;\n\n opts: {\n userConfigs: {\n [pkgRoot: string]: unknown;\n };\n globalConfig: {\n [key: string]: unknown;\n };\n // we set this when we're running inside classic ember-cli, because in that\n // case we don't have finer-grained info available about where the files\n // we're processing are globally located. When running in embroider, we\n // don't set this, because each file is visible at its full\n // globally-relevant path.\n owningPackageRoot: string | undefined;\n\n // list of packages that are under active development, represented by the\n // path to their package root directory\n isDevelopingPackageRoots: string[];\n\n // the package root directory of the app. Needed so that we can get\n // consistent answers to `isDevelopingApp` and `isDeveopingThisPackage`, as\n // well as consistent handling of Package devDependencies vs dependencies.\n appPackageRoot: string;\n\n embroiderMacrosConfigMarker: true;\n\n hideRequires: boolean;\n\n mode: 'compile-time' | 'run-time';\n };\n}\n\nexport function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State) {\n state.importUtil = new ImportUtil(t, path);\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.packageCache = RewrittenPackageCache.shared('embroider', state.opts.appPackageRoot);\n state.sourceFile = state.opts.owningPackageRoot || cleanUrl((path.hub as any).file.opts.filename);\n state.pathToOurAddon = pathToAddon;\n state.owningPackage = owningPackage;\n state.originalOwningPackage = originalOwningPackage;\n}\n\nconst runtimeAddonPath = resolve(join(__dirname, '..', 'addon'));\n\nfunction pathToAddon(this: State, moduleName: string): string {\n if (!this.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n return explicitRelative(dirname(this.sourceFile), join(runtimeAddonPath, moduleName));\n } else {\n // running inside a classic build, so use a classic-compatible runtime\n // specifier.\n //\n // CAUTION: the module we're pointing at here gets merged between all\n // present versions of @embroider/macros, and one will win. So if you are\n // introducing incompatible changes to its API, you need to change this name\n // (by tacking on a version number, etc) and rename the corresponding file\n // in ../addon.\n return `@embroider/macros/${moduleName}`;\n }\n}\n\nfunction owningPackage(this: State): Package {\n let pkg = this.packageCache.ownerOfFile(this.sourceFile);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);\n }\n return pkg;\n}\n\nfunction originalOwningPackage(this: State): Package {\n let pkg = this.owningPackage();\n return this.packageCache.original(pkg);\n}\n"]}
1
+ {"version":3,"file":"state.js","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;QACrE,yEAAyE;QACzE,4EAA4E;QAC5E,0EAA0E;QAC1E,eAAe;QACf,OAAO,qBAAqB,UAAU,EAAE,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,aAAa;IACpB,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,qBAAqB;IAC5B,IAAI,GAAG,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport { join, dirname, resolve } from 'path';\nimport type { Package } from '@embroider/shared-internals';\nimport { cleanUrl, explicitRelative, RewrittenPackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\nimport type * as Babel from '@babel/core';\n\nexport default interface State {\n importUtil: ImportUtil;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n packageCache: RewrittenPackageCache;\n sourceFile: string;\n pathToOurAddon(moduleName: string): string;\n owningPackage(): Package;\n originalOwningPackage(): Package;\n\n opts: {\n userConfigs: {\n [pkgRoot: string]: unknown;\n };\n globalConfig: {\n [key: string]: unknown;\n };\n // we set this when we're running inside classic ember-cli, because in that\n // case we don't have finer-grained info available about where the files\n // we're processing are globally located. When running in embroider, we\n // don't set this, because each file is visible at its full\n // globally-relevant path.\n owningPackageRoot: string | undefined;\n\n // list of packages that are under active development, represented by the\n // path to their package root directory\n isDevelopingPackageRoots: string[];\n\n // the package root directory of the app. Needed so that we can get\n // consistent answers to `isDevelopingApp` and `isDeveopingThisPackage`, as\n // well as consistent handling of Package devDependencies vs dependencies.\n appPackageRoot: string;\n\n embroiderMacrosConfigMarker: true;\n\n hideRequires: boolean;\n\n mode: 'compile-time' | 'run-time';\n };\n}\n\nexport function initState(t: typeof Babel, path: NodePath<Babel.types.Program>, state: State) {\n state.importUtil = new ImportUtil(t, path);\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.packageCache = RewrittenPackageCache.shared('embroider', state.opts.appPackageRoot);\n state.sourceFile = state.opts.owningPackageRoot || cleanUrl((path.hub as any).file.opts.filename);\n state.pathToOurAddon = pathToAddon;\n state.owningPackage = owningPackage;\n state.originalOwningPackage = originalOwningPackage;\n}\n\nconst runtimeAddonPath = resolve(join(__dirname, '..', 'addon'));\n\nfunction pathToAddon(this: State, moduleName: string): string {\n if (!this.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n return explicitRelative(dirname(this.sourceFile), join(runtimeAddonPath, moduleName));\n } else {\n // running inside a classic build, so use a classic-compatible runtime\n // specifier.\n //\n // CAUTION: the module we're pointing at here gets merged between all\n // present versions of @embroider/macros, and one will win. So if you are\n // introducing incompatible changes to its API, you need to change this name\n // (by tacking on a version number, etc) and rename the corresponding file\n // in ../addon.\n return `@embroider/macros/${moduleName}`;\n }\n}\n\nfunction owningPackage(this: State): Package {\n let pkg = this.packageCache.ownerOfFile(this.sourceFile);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);\n }\n return pkg;\n}\n\nfunction originalOwningPackage(this: State): Package {\n let pkg = this.owningPackage();\n return this.packageCache.original(pkg);\n}\n"]}