ember-repl 8.2.3 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/declarations/compile/Compiled.d.ts +11 -0
  2. package/declarations/compile/Compiled.d.ts.map +1 -1
  3. package/declarations/compile/compile.d.ts +9 -0
  4. package/declarations/compile/compile.d.ts.map +1 -1
  5. package/declarations/compile/state.d.ts +0 -5
  6. package/declarations/compile/state.d.ts.map +1 -1
  7. package/declarations/compile/types.d.ts +1 -1
  8. package/declarations/compile/types.d.ts.map +1 -1
  9. package/declarations/services/compiler.d.ts +22 -1
  10. package/declarations/services/compiler.d.ts.map +1 -1
  11. package/declarations/services/known-modules.d.ts +9 -0
  12. package/declarations/services/known-modules.d.ts.map +1 -1
  13. package/declarations/setup.d.ts.map +1 -1
  14. package/dist/{_commonjsHelpers-BAGoDD49.js → _commonjsHelpers-Bssqqw1Q.js} +2 -4
  15. package/dist/_commonjsHelpers-Bssqqw1Q.js.map +1 -0
  16. package/dist/compile/Compiled.js +7 -1
  17. package/dist/compile/Compiled.js.map +1 -1
  18. package/dist/compile/compile.js +0 -5
  19. package/dist/compile/compile.js.map +1 -1
  20. package/dist/compile/state.js +1 -13
  21. package/dist/compile/state.js.map +1 -1
  22. package/dist/compile/utils.js.map +1 -1
  23. package/dist/{index-DNPwtadt.js → index-CPzChcIg.js} +2 -2
  24. package/dist/{index-DNPwtadt.js.map → index-CPzChcIg.js.map} +1 -1
  25. package/dist/{index-C0sat7kP.js → index-D55gYNjO.js} +29 -8
  26. package/dist/index-D55gYNjO.js.map +1 -0
  27. package/dist/index-DNctqogm.js +70615 -0
  28. package/dist/index-DNctqogm.js.map +1 -0
  29. package/dist/{plugin-ZDtYFKJg.js → plugin-Deq-PxMR.js} +58 -37
  30. package/dist/plugin-Deq-PxMR.js.map +1 -0
  31. package/dist/services/compiler.js +90 -36
  32. package/dist/services/compiler.js.map +1 -1
  33. package/dist/services/known-modules.js +72 -60
  34. package/dist/services/known-modules.js.map +1 -1
  35. package/dist/setup.js +1 -4
  36. package/dist/setup.js.map +1 -1
  37. package/dist/test-support.js.map +1 -1
  38. package/package.json +35 -36
  39. package/src/compile/Compiled.ts +17 -0
  40. package/src/compile/compile.ts +9 -7
  41. package/src/compile/state.ts +0 -15
  42. package/src/compile/types.ts +2 -0
  43. package/src/services/compiler.ts +117 -31
  44. package/src/services/known-modules.ts +87 -56
  45. package/src/setup.ts +1 -8
  46. package/dist/_commonjsHelpers-BAGoDD49.js.map +0 -1
  47. package/dist/babel-DbH-RlNa.js +0 -106895
  48. package/dist/babel-DbH-RlNa.js.map +0 -1
  49. package/dist/index-C0sat7kP.js.map +0 -1
  50. package/dist/plugin-ZDtYFKJg.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { s as srcExports } from './index-DNPwtadt.js';
1
+ import { s as srcExports } from './index-CPzChcIg.js';
2
2
 
3
3
  function astNodeHasBinding(target, name) {
4
4
  let cursor = target;
@@ -58,7 +58,7 @@ var __classPrivateFieldGet$1 = undefined && undefined.__classPrivateFieldGet ||
58
58
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
59
59
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
60
60
  };
61
- var _ScopeLocals_instances, _ScopeLocals_mapping, _ScopeLocals_locals, _ScopeLocals_params, _ScopeLocals_isInJsScope;
61
+ var _ScopeLocals_instances, _ScopeLocals_mapping, _ScopeLocals_locals, _ScopeLocals_params, _ScopeLocals_t, _ScopeLocals_isInJsScope;
62
62
  /**
63
63
  * RFC: https://github.com/emberjs/rfcs/pull/1070
64
64
  *
@@ -112,19 +112,22 @@ const ALLOWED_GLOBALS = new Set([
112
112
  // WHATWG
113
113
  'isSecureContext']);
114
114
  class ScopeLocals {
115
- constructor(params) {
115
+ constructor(babel, params) {
116
116
  _ScopeLocals_instances.add(this);
117
+ /**
118
+ * Each hbs name maps to the JS expression that it resolves to.
119
+ * A reference to a JS binding is an Identifier.
120
+ */
117
121
  _ScopeLocals_mapping.set(this, {});
118
122
  _ScopeLocals_locals.set(this, []);
119
123
  _ScopeLocals_params.set(this, void 0);
124
+ _ScopeLocals_t.set(this, void 0);
125
+ __classPrivateFieldSet$1(this, _ScopeLocals_t, babel.types, "f");
120
126
  __classPrivateFieldSet$1(this, _ScopeLocals_params, params, "f");
121
127
  }
122
128
  get locals() {
123
129
  return readOnlyArray(__classPrivateFieldGet$1(this, _ScopeLocals_locals, "f"), 'The only supported way to manipulate locals is via the jsutils API\nhttps://github.com/emberjs/babel-plugin-ember-template-compilation#jsutils-manipulating-javascript-from-within-ast-transforms');
124
130
  }
125
- has(key) {
126
- return key in __classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f");
127
- }
128
131
  get(key) {
129
132
  return __classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f")[key];
130
133
  }
@@ -134,8 +137,8 @@ class ScopeLocals {
134
137
  entries() {
135
138
  return Object.entries(__classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f"));
136
139
  }
137
- add(hbsName, jsName) {
138
- __classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f")[hbsName] = jsName ?? hbsName;
140
+ add(hbsName, jsValue) {
141
+ __classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f")[hbsName] = jsValue ?? (hbsName === 'this' ? __classPrivateFieldGet$1(this, _ScopeLocals_t, "f").thisExpression() : __classPrivateFieldGet$1(this, _ScopeLocals_t, "f").identifier(hbsName));
139
142
  if (!__classPrivateFieldGet$1(this, _ScopeLocals_locals, "f").includes(hbsName)) {
140
143
  __classPrivateFieldGet$1(this, _ScopeLocals_locals, "f").push(hbsName);
141
144
  }
@@ -209,9 +212,8 @@ class ScopeLocals {
209
212
  };
210
213
  }
211
214
  }
212
- _ScopeLocals_mapping = new WeakMap(), _ScopeLocals_locals = new WeakMap(), _ScopeLocals_params = new WeakMap(), _ScopeLocals_instances = new WeakSet(), _ScopeLocals_isInJsScope = function _ScopeLocals_isInJsScope(hbsName, jsPath) {
213
- let jsName = __classPrivateFieldGet$1(this, _ScopeLocals_mapping, "f")[hbsName] ?? hbsName;
214
- return ALLOWED_GLOBALS.has(jsName) || jsPath.scope.getBinding(jsName);
215
+ _ScopeLocals_mapping = new WeakMap(), _ScopeLocals_locals = new WeakMap(), _ScopeLocals_params = new WeakMap(), _ScopeLocals_t = new WeakMap(), _ScopeLocals_instances = new WeakSet(), _ScopeLocals_isInJsScope = function _ScopeLocals_isInJsScope(hbsName, jsPath) {
216
+ return ALLOWED_GLOBALS.has(hbsName) || jsPath.scope.getBinding(hbsName);
215
217
  };
216
218
 
217
219
  class ExpressionParser {
@@ -288,18 +290,12 @@ class ExpressionParser {
288
290
  throw path.buildCodeFrameError(`Scope objects for \`${invokedName}\` may only contain static property names`);
289
291
  }
290
292
  let propName = name$1(key);
291
- switch (value.type) {
292
- case 'Identifier':
293
- res.add(propName, value.name);
294
- break;
295
- case 'ThisExpression':
296
- res.add(propName, 'this');
297
- break;
298
- default:
299
- throw path.buildCodeFrameError(`Scope objects for \`${invokedName}\` may only contain direct references to in-scope values, e.g. { ${propName} } or { ${propName}: ${propName} }. Found ${value.type}`);
293
+ if (!this.t.isExpression(value)) {
294
+ throw path.buildCodeFrameError(`Scope objects for \`${invokedName}\` may only contain expressions. Found ${value.type}`);
300
295
  }
296
+ res.add(propName, value);
301
297
  return res;
302
- }, new ScopeLocals({
298
+ }, new ScopeLocals(this.babel, {
303
299
  mode: 'explicit'
304
300
  }));
305
301
  }
@@ -8827,9 +8823,9 @@ function runtimeErrorIIFE(babel, replacements) {
8827
8823
  let statement = babel.template(`(function() {\n throw new Error('ERROR_MESSAGE');\n})();`)(replacements);
8828
8824
  return statement.expression;
8829
8825
  }
8830
- function buildScopeLocals(userTypedOptions, formatOptions, target, mayUseLexicalThis) {
8826
+ function buildScopeLocals(babel, userTypedOptions, formatOptions, target, mayUseLexicalThis) {
8831
8827
  if (formatOptions.rfc931Support && userTypedOptions.eval) {
8832
- return new ScopeLocals({
8828
+ return new ScopeLocals(babel, {
8833
8829
  mode: 'implicit',
8834
8830
  jsPath: target,
8835
8831
  mayUseLexicalThis
@@ -8837,7 +8833,7 @@ function buildScopeLocals(userTypedOptions, formatOptions, target, mayUseLexical
8837
8833
  } else if (userTypedOptions.scope) {
8838
8834
  return userTypedOptions.scope;
8839
8835
  } else {
8840
- return new ScopeLocals({
8836
+ return new ScopeLocals(babel, {
8841
8837
  mode: 'explicit'
8842
8838
  });
8843
8839
  }
@@ -8876,22 +8872,45 @@ function buildPrecompileOptions(babel, target, state, normalizedOpts, template,
8876
8872
  function remapAndBindIdentifiers(target, babel, scopeLocals) {
8877
8873
  target.traverse({
8878
8874
  Identifier(path) {
8879
- if (scopeLocals.has(path.node.name) && path.node.name !== scopeLocals.get(path.node.name)) {
8880
- // this identifier has different names in hbs vs js, so we need to
8881
- // replace the hbs name in the template compiler output with the js
8882
- // name
8883
- path.replaceWith(babel.types.identifier(scopeLocals.get(path.node.name)));
8875
+ if (!path.isReferencedIdentifier()) {
8876
+ // only references get remapped. When the compiler emits the wire
8877
+ // format's scope as an object (`scope: () => ({ foo })`) rather than
8878
+ // an array, the local's name also appears as a property key, and
8879
+ // rewriting it there would drop the name the template refers to.
8880
+ return;
8881
+ }
8882
+ let jsValue = scopeLocals.get(path.node.name);
8883
+ if (jsValue && !babel.types.isIdentifier(jsValue, {
8884
+ name: path.node.name
8885
+ })) {
8886
+ let [replacement] = path.replaceWith(babel.types.cloneNode(jsValue, true));
8887
+ /**
8888
+ * The names inside the new expression are JS names, not hbs names,
8889
+ * so they must not be remapped again. Without the skip:
8890
+ *
8891
+ * `{ a: f(a) }` loops forever
8892
+ * `{ a: b, b: c }` a resolves to c
8893
+ */
8894
+ replacement.skip();
8895
+ // this is where we tell babel's scope system about the new references
8896
+ // we just introduced. @babel/plugin-transform-typescript in particular
8897
+ // cares a lot about those references being present.
8898
+ bindReference(replacement);
8899
+ replacement.traverse({
8900
+ ReferencedIdentifier: bindReference
8901
+ });
8884
8902
  }
8885
- // this is where we tell babel's scope system about the new reference we
8886
- // just introduced. @babel/plugin-transform-typescript in particular
8887
- // cares a lot about those references being present.
8888
- path.scope.getBinding(path.node.name)?.reference(path);
8889
8903
  }
8890
8904
  });
8891
8905
  }
8906
+ function bindReference(path) {
8907
+ if (path.isIdentifier() && path.isReferencedIdentifier()) {
8908
+ path.scope.getBinding(path.node.name)?.reference(path);
8909
+ }
8910
+ }
8892
8911
  function insertCompiledTemplate(babel, state, opts, template, target, userTypedOptions, config, backingClass) {
8893
8912
  let t = babel.types;
8894
- let scopeLocals = buildScopeLocals(userTypedOptions, config, target, !backingClass);
8913
+ let scopeLocals = buildScopeLocals(babel, userTypedOptions, config, target, !backingClass);
8895
8914
  let options = buildPrecompileOptions(babel, target, state, opts, template, userTypedOptions, config, scopeLocals);
8896
8915
  let precompileResultString;
8897
8916
  // insertRuntimeErrors is legacy and not supported by the newer rfc931 form
@@ -8921,7 +8940,7 @@ function insertCompiledTemplate(babel, state, opts, template, target, userTypedO
8921
8940
  }
8922
8941
  function insertTransformedTemplate(babel, state, normalizedOpts, template, target, userTypedOptions, formatOptions, backingClass) {
8923
8942
  let t = babel.types;
8924
- let scopeLocals = buildScopeLocals(userTypedOptions, formatOptions, target, !backingClass);
8943
+ let scopeLocals = buildScopeLocals(babel, userTypedOptions, formatOptions, target, !backingClass);
8925
8944
  let options = buildPrecompileOptions(babel, target, state, normalizedOpts, template, userTypedOptions, formatOptions, scopeLocals);
8926
8945
  let ast = Qt(template, {
8927
8946
  ...options,
@@ -8994,7 +9013,9 @@ function templateFactoryConfig(opts) {
8994
9013
  }
8995
9014
  function buildScope(babel, locals) {
8996
9015
  let t = babel.types;
8997
- return t.arrowFunctionExpression([], t.objectExpression(locals.entries().map(([name, identifier]) => t.objectProperty(t.identifier(name), t.identifier(identifier), false, name !== 'this'))));
9016
+ return t.arrowFunctionExpression([], t.objectExpression(locals.entries().map(([name, value]) => t.objectProperty(t.identifier(name), t.cloneNode(value, true), false, t.isIdentifier(value, {
9017
+ name
9018
+ })))));
8998
9019
  }
8999
9020
  // this is responsible both for adjusting the AST for our scope argument *and*
9000
9021
  // ensuring that babel's scope system will see that these new identifiers
@@ -9101,4 +9122,4 @@ function name(node) {
9101
9122
  var plugin = makePlugin(async options => options);
9102
9123
 
9103
9124
  export { plugin as default, makePlugin };
9104
- //# sourceMappingURL=plugin-ZDtYFKJg.js.map
9125
+ //# sourceMappingURL=plugin-Deq-PxMR.js.map