@embroider/macros 1.19.2 → 1.19.3

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.19.2",
3
+ "version": "1.19.3",
4
4
  "private": false,
5
5
  "description": "Standardized build-time macros for ember apps.",
6
6
  "keywords": [
@@ -55,7 +55,7 @@
55
55
  "typescript": "^5.4.5",
56
56
  "vitest": "^3.2.4",
57
57
  "@embroider/test-support": "0.36.0",
58
- "@embroider/core": "4.2.5"
58
+ "@embroider/core": "4.2.6"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@glint/template": "^1.0.0"
@@ -35,7 +35,7 @@ function macroCondition(macro, state) {
35
35
  let consequent = macro.conditional.get('consequent');
36
36
  let alternate = macro.conditional.get('alternate');
37
37
  if (state.opts.mode === 'run-time' && predicate.hasRuntimeImplementation !== false) {
38
- let callee = macro.conditional.get('test').get('callee');
38
+ let callee = macro.callExpression.get('callee');
39
39
  callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'macroCondition'));
40
40
  }
41
41
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"macro-condition.js","sourceRoot":"","sources":["macro-condition.ts"],"names":[],"mappings":";;;;;AAYA,gEAkBC;AAED,iCA8BC;AA7DD,mDAA4C;AAE5C,oDAA4B;AAS5B,SAAgB,0BAA0B,CACxC,IAAuD;IAEvD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5B,IAAI,IAAI,CAAC,iBAAiB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QAC3D,MAAM,GAAG,KAAK,CAAC;QACf,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED,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AAC,MAAM,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACzG,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GACjB,SAAS,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAC3G,IAAI,IAAI,EAAE,CAAC;YACT,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QAC7B,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { Evaluator } from './evaluate-json';\nimport type { types as t } from '@babel/core';\nimport error from './error';\nimport type State from './state';\n\nexport interface MacroCondition {\n parity: boolean;\n conditional: NodePath<t.IfStatement | t.ConditionalExpression>;\n callExpression: NodePath<t.CallExpression>;\n}\n\nexport function identifyMacroConditionPath(\n path: NodePath<t.IfStatement | t.ConditionalExpression>\n): MacroCondition | false {\n let parity = true;\n let test = path.get('test');\n\n if (test.isUnaryExpression() && test.node.operator === '!') {\n parity = false;\n test = test.get('argument');\n }\n\n if (test.isCallExpression()) {\n let callee = test.get('callee');\n if (callee.referencesImport('@embroider/macros', 'macroCondition')) {\n return { parity, conditional: path, callExpression: test };\n }\n }\n return false;\n}\n\nexport default function macroCondition(macro: MacroCondition, state: State) {\n let args = macro.callExpression.get('arguments');\n if (args.length !== 1) {\n throw error(macro.conditional, `macroCondition accepts exactly one argument, you passed ${args.length}`);\n }\n\n let [predicatePath] = args;\n let predicate = new Evaluator({ state }).evaluate(predicatePath);\n if (!predicate.confident) {\n throw error(args[0], `the first argument to macroCondition must be statically known`);\n }\n\n let consequent = macro.conditional.get('consequent');\n let alternate = macro.conditional.get('alternate');\n\n if (state.opts.mode === 'run-time' && predicate.hasRuntimeImplementation !== false) {\n let callee = macro.conditional.get('test').get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'macroCondition'));\n } else {\n let [kept, removed] =\n predicate.value === macro.parity ? [consequent.node, alternate.node] : [alternate.node, consequent.node];\n if (kept) {\n macro.conditional.replaceWith(kept);\n } else {\n macro.conditional.remove();\n }\n if (removed) {\n state.removed.add(removed);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"macro-condition.js","sourceRoot":"","sources":["macro-condition.ts"],"names":[],"mappings":";;;;;AAYA,gEAkBC;AAED,iCA8BC;AA7DD,mDAA4C;AAE5C,oDAA4B;AAS5B,SAAgB,0BAA0B,CACxC,IAAuD;IAEvD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5B,IAAI,IAAI,CAAC,iBAAiB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QAC3D,MAAM,GAAG,KAAK,CAAC;QACf,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAC;QAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,gBAAgB,C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,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GACjB,SAAS,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAC3G,IAAI,IAAI,EAAE,CAAC;YACT,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QAC7B,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { Evaluator } from './evaluate-json';\nimport type { types as t } from '@babel/core';\nimport error from './error';\nimport type State from './state';\n\nexport interface MacroCondition {\n parity: boolean;\n conditional: NodePath<t.IfStatement | t.ConditionalExpression>;\n callExpression: NodePath<t.CallExpression>;\n}\n\nexport function identifyMacroConditionPath(\n path: NodePath<t.IfStatement | t.ConditionalExpression>\n): MacroCondition | false {\n let parity = true;\n let test = path.get('test');\n\n if (test.isUnaryExpression() && test.node.operator === '!') {\n parity = false;\n test = test.get('argument');\n }\n\n if (test.isCallExpression()) {\n let callee = test.get('callee');\n if (callee.referencesImport('@embroider/macros', 'macroCondition')) {\n return { parity, conditional: path, callExpression: test };\n }\n }\n return false;\n}\n\nexport default function macroCondition(macro: MacroCondition, state: State) {\n let args = macro.callExpression.get('arguments');\n if (args.length !== 1) {\n throw error(macro.conditional, `macroCondition accepts exactly one argument, you passed ${args.length}`);\n }\n\n let [predicatePath] = args;\n let predicate = new Evaluator({ state }).evaluate(predicatePath);\n if (!predicate.confident) {\n throw error(args[0], `the first argument to macroCondition must be statically known`);\n }\n\n let consequent = macro.conditional.get('consequent');\n let alternate = macro.conditional.get('alternate');\n\n if (state.opts.mode === 'run-time' && predicate.hasRuntimeImplementation !== false) {\n let callee = macro.callExpression.get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'macroCondition'));\n } else {\n let [kept, removed] =\n predicate.value === macro.parity ? [consequent.node, alternate.node] : [alternate.node, consequent.node];\n if (kept) {\n macro.conditional.replaceWith(kept);\n } else {\n macro.conditional.remove();\n }\n if (removed) {\n state.removed.add(removed);\n }\n }\n}\n"]}