ember-vite-hmr 1.0.0 → 1.1.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.
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.hotAstProcessor = void 0;
27
+ const core_1 = require("@babel/core");
27
28
  const glimmer = __importStar(require("@glimmer/syntax"));
28
29
  const babel_import_util_1 = require("babel-import-util");
29
30
  const builtInComponents = ['LinkTo'];
@@ -209,6 +210,7 @@ function hotReplaceAst({ types: t }) {
209
210
  },
210
211
  visitor: {
211
212
  Program(path, state) {
213
+ var _a, _b;
212
214
  if (!exports.hotAstProcessor.meta.importVar) {
213
215
  return;
214
216
  }
@@ -226,6 +228,23 @@ function hotReplaceAst({ types: t }) {
226
228
  const varDeclaration = path.node.body.findIndex((e) => e.type === 'VariableDeclaration' && e.declarations[0].id.name === exports.hotAstProcessor.meta.importVar) + 1;
227
229
  const lastImportIndex = path.node.body.findLastIndex((e) => e.type === 'ImportDeclaration') + 1;
228
230
  path.node.body.splice(Math.max(varDeclaration, lastImportIndex), 0, assign);
231
+ const findImport = function findImport(specifier) {
232
+ return path.node.body.find(b => b.type === 'ImportDeclaration' && b.specifiers.some(s => s.local.name === specifier));
233
+ };
234
+ const hotAccepts = [];
235
+ for (const imp of bindings) {
236
+ const importDeclaration = findImport(imp);
237
+ const source = importDeclaration.source.value;
238
+ const specifier = importDeclaration.specifiers.find((s) => s.local.name === imp);
239
+ const specifierName = ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) ||
240
+ ((_b = specifier.imported) === null || _b === void 0 ? void 0 : _b.value) ||
241
+ 'default';
242
+ const ast = (0, core_1.parse)(`import.meta.hot.accept('${source}', (module) => (${exports.hotAstProcessor.meta.importVar}.${imp}=module['${specifierName}']))`);
243
+ const impHot = ast === null || ast === void 0 ? void 0 : ast.program.body[0];
244
+ hotAccepts.push(impHot);
245
+ }
246
+ const ifHot = t.ifStatement(t.memberExpression(t.metaProperty(t.identifier('import'), t.identifier('meta')), t.identifier('hot')), t.blockStatement([...hotAccepts]));
247
+ path.node.body.push(ifHot);
229
248
  }
230
249
  },
231
250
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-vite-hmr",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "keywords": [
5
5
  "ember-addon"
6
6
  ],