@parcel/transformer-react-refresh-wrap 2.0.0-nightly.149 → 2.0.0-nightly.1491

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.
@@ -4,141 +4,60 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _semver = _interopRequireDefault(require("semver"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _plugin = require("@parcel/plugin");
13
-
14
- var _utils = require("@parcel/utils");
15
-
16
- var _sourceMap = _interopRequireDefault(require("@parcel/source-map"));
17
-
18
- var _generator = _interopRequireDefault(require("@babel/generator"));
19
-
20
- var _parser = require("@babel/parser");
21
-
22
- var _template = _interopRequireDefault(require("@babel/template"));
23
-
24
- var t = _interopRequireWildcard(require("@babel/types"));
25
-
26
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
-
28
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- const WRAPPER = _path.default.join(__dirname, 'helpers', 'helpers.js');
33
-
34
- const wrapper = _template.default.statements(`
35
- var helpers = require(%%helper%%);
36
- var prevRefreshReg = window.$RefreshReg$;
37
- var prevRefreshSig = window.$RefreshSig$;
38
- helpers.prelude(module);
39
-
40
- try {
41
- %%module%%
42
- helpers.postlude(module);
43
- } finally {
44
- window.$RefreshReg$ = prevRefreshReg;
45
- window.$RefreshSig$ = prevRefreshSig;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
46
13
  }
47
- `);
48
-
14
+ function _plugin() {
15
+ const data = require("@parcel/plugin");
16
+ _plugin = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
22
  function shouldExclude(asset, options) {
50
- return !asset.isSource || !options.hot || !asset.env.isBrowser() || options.mode !== 'development' || !asset.getDependencies().find(v => v.moduleSpecifier === 'react');
23
+ return !asset.isSource || !options.hmrOptions || !asset.env.isBrowser() || asset.env.isLibrary || asset.env.isWorker() || asset.env.isWorklet() || options.mode !== 'development' || !asset.getDependencies().find(v => v.specifier === 'react' || v.specifier === 'react/jsx-runtime' || v.specifier === 'react/jsx-dev-runtime' || v.specifier === '@emotion/react' || v.specifier === '@emotion/react/jsx-runtime' || v.specifier === '@emotion/react/jsx-dev-runtime');
51
24
  }
52
-
53
- var _default = new _plugin.Transformer({
54
- canReuseAST({
55
- ast
56
- }) {
57
- return ast.type === 'babel' && _semver.default.satisfies(ast.version, '^7.0.0');
58
- },
59
-
60
- async parse({
25
+ var _default = exports.default = new (_plugin().Transformer)({
26
+ async transform({
61
27
  asset,
62
28
  options
63
29
  }) {
64
30
  if (shouldExclude(asset, options)) {
65
- return null;
66
- }
67
-
68
- let code = await asset.getCode();
69
- return {
70
- type: 'babel',
71
- version: '7.0.0',
72
- isDirty: false,
73
- program: (0, _parser.parse)(code, {
74
- sourceFilename: this.name,
75
- allowReturnOutsideFunction: true,
76
- strictMode: false,
77
- sourceType: 'module',
78
- plugins: ['exportDefaultFrom', 'exportNamespaceFrom', 'dynamicImport']
79
- })
80
- };
81
- },
82
-
83
- transform({
84
- asset,
85
- options
86
- }) {
87
- let ast = asset.ast;
88
-
89
- if (!ast || shouldExclude(asset, options)) {
90
31
  return [asset];
91
32
  }
33
+ let wrapperPath = `@parcel/transformer-react-refresh-wrap/${_path().default.basename(__dirname)}/helpers/helpers.js`;
34
+ let code = await asset.getCode();
35
+ let map = await asset.getMap();
36
+ let name = `$parcel$ReactRefreshHelpers$${asset.id.slice(-4)}`;
37
+ code = `var ${name} = require(${JSON.stringify(wrapperPath)});
38
+ var prevRefreshReg = window.$RefreshReg$;
39
+ var prevRefreshSig = window.$RefreshSig$;
40
+ ${name}.prelude(module);
92
41
 
93
- let wrapperPath = _path.default.relative(_path.default.dirname(asset.filePath), WRAPPER).replace(/\\/g, '/');
94
-
95
- if (!wrapperPath.startsWith('.')) {
96
- wrapperPath = './' + wrapperPath;
42
+ try {
43
+ ${code}
44
+ ${name}.postlude(module);
45
+ } finally {
46
+ window.$RefreshReg$ = prevRefreshReg;
47
+ window.$RefreshSig$ = prevRefreshSig;
48
+ }`;
49
+ asset.setCode(code);
50
+ if (map) {
51
+ map.offsetLines(1, 6);
52
+ asset.setMap(map);
97
53
  }
98
54
 
99
- ast.program.program.body = wrapper({
100
- helper: t.stringLiteral(wrapperPath),
101
- module: ast.program.program.body
102
- });
103
- ast.isDirty = true; // The JSTransformer has already run, do it manually
104
-
55
+ // The JSTransformer has already run, do it manually
105
56
  asset.addDependency({
106
- moduleSpecifier: wrapperPath
57
+ specifier: wrapperPath,
58
+ specifierType: 'esm',
59
+ resolveFrom: __filename
107
60
  });
108
61
  return [asset];
109
- },
110
-
111
- async generate({
112
- asset,
113
- options
114
- }) {
115
- let code = await asset.getCode();
116
- let res = {
117
- code
118
- };
119
- let ast = asset.ast;
120
-
121
- if (ast && ast.isDirty !== false) {
122
- let sourceFileName = (0, _utils.relativeUrl)(options.projectRoot, asset.filePath);
123
- let generated = (0, _generator.default)(ast.program, {
124
- sourceMaps: options.sourceMaps,
125
- sourceFileName: sourceFileName
126
- }, code);
127
- res.code = generated.code; // $FlowFixMe...
128
-
129
- res.map = new _sourceMap.default(generated.rawMappings, {
130
- [sourceFileName]: null
131
- });
132
- }
133
-
134
- if (asset.meta.globals && asset.meta.globals.size > 0) {
135
- res.code = Array.from(asset.meta.globals.values()).map(g => g ? g.code : '').join('\n') + '\n' + res.code;
136
- }
137
-
138
- delete asset.meta.globals;
139
- return res;
140
62
  }
141
-
142
- });
143
-
144
- exports.default = _default;
63
+ });
@@ -1,27 +1,39 @@
1
1
  "use strict";
2
2
 
3
3
  var Refresh = require('react-refresh/runtime');
4
-
5
4
  function debounce(func, delay) {
6
5
  if (process.env.NODE_ENV === 'test') {
7
6
  return function (args) {
8
7
  func.call(null, args);
9
8
  };
10
9
  } else {
11
- var timeout = undefined;
10
+ let timeout = undefined;
11
+ let lastTime = 0;
12
12
  return function (args) {
13
- clearTimeout(timeout);
14
- timeout = setTimeout(function () {
15
- timeout = undefined;
13
+ // Call immediately if last call was more than the delay ago.
14
+ // Otherwise, set a timeout. This means the first call is fast
15
+ // (for the common case of a single update), and subsequent updates
16
+ // are batched.
17
+ let now = Date.now();
18
+ if (now - lastTime > delay) {
19
+ lastTime = now;
16
20
  func.call(null, args);
17
- }, delay);
21
+ } else {
22
+ clearTimeout(timeout);
23
+ timeout = setTimeout(function () {
24
+ timeout = undefined;
25
+ lastTime = Date.now();
26
+ func.call(null, args);
27
+ }, delay);
28
+ }
18
29
  };
19
30
  }
20
31
  }
21
-
22
32
  var enqueueUpdate = debounce(function () {
23
33
  Refresh.performReactRefresh();
24
- }, 30); // Everthing below is either adapted or copied from
34
+ }, 30);
35
+
36
+ // Everthing below is either adapted or copied from
25
37
  // https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js
26
38
  // MIT License - Copyright (c) Facebook, Inc. and its affiliates.
27
39
 
@@ -29,158 +41,133 @@ module.exports.prelude = function (module) {
29
41
  window.$RefreshReg$ = function (type, id) {
30
42
  Refresh.register(type, module.id + ' ' + id);
31
43
  };
32
-
33
44
  window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform;
34
45
  };
35
-
36
46
  module.exports.postlude = function (module) {
37
47
  if (isReactRefreshBoundary(module.exports)) {
38
48
  registerExportsForReactRefresh(module);
39
- module.hot.dispose(function (data) {
40
- data.prevExports = module.exports;
41
- });
42
- module.hot.accept(function (getParents) {
43
- var prevExports = module.hot.data.prevExports;
44
- var nextExports = module.exports; // Since we just executed the code for it, it's possible
45
- // that the new exports make it ineligible for being a boundary.
46
-
47
- var isNoLongerABoundary = !isReactRefreshBoundary(nextExports); // It can also become ineligible if its exports are incompatible
48
- // with the previous exports.
49
- // For example, if you add/remove/change exports, we'll want
50
- // to re-execute the importing modules, and force those components
51
- // to re-render. Similarly, if you convert a class component
52
- // to a function, we want to invalidate the boundary.
53
-
54
- var didInvalidate = shouldInvalidateReactRefreshBoundary(prevExports, nextExports);
55
-
56
- if (isNoLongerABoundary || didInvalidate) {
57
- // We'll be conservative. The only case in which we won't do a full
58
- // reload is if all parent modules are also refresh boundaries.
59
- // In that case we'll add them to the current queue.
60
- var parents = getParents();
61
-
62
- if (parents.length === 0) {
63
- // Looks like we bubbled to the root. Can't recover from that.
49
+ if (module.hot) {
50
+ module.hot.dispose(function (data) {
51
+ if (Refresh.hasUnrecoverableErrors()) {
64
52
  window.location.reload();
65
- return;
66
53
  }
67
-
68
- return parents;
69
- }
70
-
71
- enqueueUpdate();
72
- });
73
-
74
- if (Refresh.hasUnrecoverableErrors()) {
75
- window.location.reload();
54
+ data.prevExports = module.exports;
55
+ });
56
+ module.hot.accept(function (getParents) {
57
+ var prevExports = module.hot.data.prevExports;
58
+ var nextExports = module.exports;
59
+ // Since we just executed the code for it, it's possible
60
+ // that the new exports make it ineligible for being a boundary.
61
+ var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
62
+ // It can also become ineligible if its exports are incompatible
63
+ // with the previous exports.
64
+ // For example, if you add/remove/change exports, we'll want
65
+ // to re-execute the importing modules, and force those components
66
+ // to re-render. Similarly, if you convert a class component
67
+ // to a function, we want to invalidate the boundary.
68
+ var didInvalidate = shouldInvalidateReactRefreshBoundary(prevExports, nextExports);
69
+ if (isNoLongerABoundary || didInvalidate) {
70
+ // We'll be conservative. The only case in which we won't do a full
71
+ // reload is if all parent modules are also refresh boundaries.
72
+ // In that case we'll add them to the current queue.
73
+ var parents = getParents();
74
+ if (parents.length === 0) {
75
+ // Looks like we bubbled to the root. Can't recover from that.
76
+ window.location.reload();
77
+ return;
78
+ }
79
+ return parents;
80
+ }
81
+ enqueueUpdate();
82
+ });
76
83
  }
77
84
  }
78
85
  };
79
-
80
86
  function isReactRefreshBoundary(exports) {
81
87
  if (Refresh.isLikelyComponentType(exports)) {
82
88
  return true;
83
89
  }
84
-
85
90
  if (exports == null || typeof exports !== 'object') {
86
91
  // Exit if we can't iterate over exports.
87
92
  return false;
88
93
  }
89
-
90
94
  var hasExports = false;
91
95
  var areAllExportsComponents = true;
92
-
96
+ let isESM = ('__esModule' in exports);
93
97
  for (var key in exports) {
94
98
  hasExports = true;
95
-
96
99
  if (key === '__esModule') {
97
100
  continue;
98
101
  }
99
-
100
102
  var desc = Object.getOwnPropertyDescriptor(exports, key);
101
-
102
- if (desc && desc.get) {
103
- // Don't invoke getters as they may have side effects.
103
+ if (desc && desc.get && !isESM) {
104
+ // Don't invoke getters for CJS as they may have side effects.
104
105
  return false;
105
106
  }
106
-
107
107
  var exportValue = exports[key];
108
-
109
108
  if (!Refresh.isLikelyComponentType(exportValue)) {
110
109
  areAllExportsComponents = false;
111
110
  }
112
111
  }
113
-
114
112
  return hasExports && areAllExportsComponents;
115
113
  }
116
-
117
114
  function shouldInvalidateReactRefreshBoundary(prevExports, nextExports) {
118
115
  var prevSignature = getRefreshBoundarySignature(prevExports);
119
116
  var nextSignature = getRefreshBoundarySignature(nextExports);
120
-
121
117
  if (prevSignature.length !== nextSignature.length) {
122
118
  return true;
123
119
  }
124
-
125
120
  for (var i = 0; i < nextSignature.length; i++) {
126
121
  if (prevSignature[i] !== nextSignature[i]) {
127
122
  return true;
128
123
  }
129
124
  }
130
-
131
125
  return false;
132
- } // When this signature changes, it's unsafe to stop at this refresh boundary.
133
-
126
+ }
134
127
 
128
+ // When this signature changes, it's unsafe to stop at this refresh boundary.
135
129
  function getRefreshBoundarySignature(exports) {
136
130
  var signature = [];
137
131
  signature.push(Refresh.getFamilyByType(exports));
138
-
139
132
  if (exports == null || typeof exports !== 'object') {
140
133
  // Exit if we can't iterate over exports.
141
134
  // (This is important for legacy environments.)
142
135
  return signature;
143
136
  }
144
-
137
+ let isESM = ('__esModule' in exports);
145
138
  for (var key in exports) {
146
139
  if (key === '__esModule') {
147
140
  continue;
148
141
  }
149
-
150
142
  var desc = Object.getOwnPropertyDescriptor(exports, key);
151
-
152
- if (desc && desc.get) {
143
+ if (desc && desc.get && !isESM) {
144
+ // Don't invoke getters for CJS as they may have side effects.
153
145
  continue;
154
146
  }
155
-
156
147
  var exportValue = exports[key];
157
148
  signature.push(key);
158
149
  signature.push(Refresh.getFamilyByType(exportValue));
159
150
  }
160
-
161
151
  return signature;
162
152
  }
163
-
164
153
  function registerExportsForReactRefresh(module) {
165
154
  var exports = module.exports,
166
- id = module.id;
155
+ id = module.id;
167
156
  Refresh.register(exports, id + ' %exports%');
168
-
169
157
  if (exports == null || typeof exports !== 'object') {
170
158
  // Exit if we can't iterate over exports.
171
159
  // (This is important for legacy environments.)
172
160
  return;
173
161
  }
174
-
162
+ let isESM = ('__esModule' in exports);
175
163
  for (var key in exports) {
176
164
  var desc = Object.getOwnPropertyDescriptor(exports, key);
177
-
178
- if (desc && desc.get) {
179
- // Don't invoke getters as they may have side effects.
165
+ if (desc && desc.get && !isESM) {
166
+ // Don't invoke getters for CJS as they may have side effects.
180
167
  continue;
181
168
  }
182
-
183
169
  var exportValue = exports[key];
184
- Refresh.register(exportValue, id + ' %exports% ' + key);
170
+ var typeID = id + ' %exports% ' + key;
171
+ Refresh.register(exportValue, typeID);
185
172
  }
186
173
  }
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@parcel/transformer-react-refresh-wrap",
3
- "version": "2.0.0-nightly.149+453f7b0b",
3
+ "version": "2.0.0-nightly.1491+fdf495ba3",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/parcel"
11
+ },
8
12
  "repository": {
9
13
  "type": "git",
10
14
  "url": "https://github.com/parcel-bundler/parcel.git"
@@ -12,19 +16,13 @@
12
16
  "main": "lib/ReactRefreshWrapTransformer.js",
13
17
  "source": "src/ReactRefreshWrapTransformer.js",
14
18
  "engines": {
15
- "node": ">= 10.0.0",
16
- "parcel": "^2.0.0-alpha.1.1"
19
+ "node": ">= 12.0.0",
20
+ "parcel": "2.0.0-nightly.1489+fdf495ba3"
17
21
  },
18
22
  "dependencies": {
19
- "@babel/generator": "^7.0.0",
20
- "@babel/parser": "^7.0.0",
21
- "@babel/template": "^7.0.0",
22
- "@babel/types": "^7.0.0",
23
- "@parcel/plugin": "2.0.0-nightly.149+453f7b0b",
24
- "@parcel/source-map": "2.0.0-nightly.149+453f7b0b",
25
- "@parcel/utils": "2.0.0-nightly.149+453f7b0b",
26
- "react-refresh": "^0.6.0",
27
- "semver": "^5.4.1"
23
+ "@parcel/plugin": "2.0.0-nightly.1491+fdf495ba3",
24
+ "@parcel/utils": "2.0.0-nightly.1491+fdf495ba3",
25
+ "react-refresh": "^0.9.0"
28
26
  },
29
- "gitHead": "453f7b0bf295e6a7cbec5d24fab4c48e21e6168f"
27
+ "gitHead": "fdf495ba3c8ed727d10e87cc9697bc9ef5ec997a"
30
28
  }
@@ -1,138 +1,71 @@
1
1
  // @flow
2
2
 
3
- import type {StringLiteral, Statement} from '@babel/types';
4
-
5
- import semver from 'semver';
6
3
  import path from 'path';
7
4
  import {Transformer} from '@parcel/plugin';
8
- import {relativeUrl} from '@parcel/utils';
9
- import SourceMap from '@parcel/source-map';
10
- import generate from '@babel/generator';
11
- import {parse} from '@babel/parser';
12
- import template from '@babel/template';
13
- import * as t from '@babel/types';
14
-
15
- const WRAPPER = path.join(__dirname, 'helpers', 'helpers.js');
16
-
17
- const wrapper = template.statements<{|
18
- helper: StringLiteral,
19
- module: Array<Statement>,
20
- |}>(`
21
- var helpers = require(%%helper%%);
22
- var prevRefreshReg = window.$RefreshReg$;
23
- var prevRefreshSig = window.$RefreshSig$;
24
- helpers.prelude(module);
25
-
26
- try {
27
- %%module%%
28
- helpers.postlude(module);
29
- } finally {
30
- window.$RefreshReg$ = prevRefreshReg;
31
- window.$RefreshSig$ = prevRefreshSig;
32
- }
33
- `);
34
5
 
35
6
  function shouldExclude(asset, options) {
36
7
  return (
37
8
  !asset.isSource ||
38
- !options.hot ||
9
+ !options.hmrOptions ||
39
10
  !asset.env.isBrowser() ||
11
+ asset.env.isLibrary ||
12
+ asset.env.isWorker() ||
13
+ asset.env.isWorklet() ||
40
14
  options.mode !== 'development' ||
41
- !asset.getDependencies().find(v => v.moduleSpecifier === 'react')
15
+ !asset
16
+ .getDependencies()
17
+ .find(
18
+ v =>
19
+ v.specifier === 'react' ||
20
+ v.specifier === 'react/jsx-runtime' ||
21
+ v.specifier === 'react/jsx-dev-runtime' ||
22
+ v.specifier === '@emotion/react' ||
23
+ v.specifier === '@emotion/react/jsx-runtime' ||
24
+ v.specifier === '@emotion/react/jsx-dev-runtime',
25
+ )
42
26
  );
43
27
  }
44
28
 
45
- export default new Transformer({
46
- canReuseAST({ast}) {
47
- return ast.type === 'babel' && semver.satisfies(ast.version, '^7.0.0');
48
- },
49
-
50
- async parse({asset, options}) {
29
+ export default (new Transformer({
30
+ async transform({asset, options}) {
51
31
  if (shouldExclude(asset, options)) {
52
- return null;
32
+ return [asset];
53
33
  }
54
34
 
35
+ let wrapperPath = `@parcel/transformer-react-refresh-wrap/${path.basename(
36
+ __dirname,
37
+ )}/helpers/helpers.js`;
38
+
55
39
  let code = await asset.getCode();
56
- return {
57
- type: 'babel',
58
- version: '7.0.0',
59
- isDirty: false,
60
- program: parse(code, {
61
- sourceFilename: this.name,
62
- allowReturnOutsideFunction: true,
63
- strictMode: false,
64
- sourceType: 'module',
65
- plugins: ['exportDefaultFrom', 'exportNamespaceFrom', 'dynamicImport'],
66
- }),
67
- };
68
- },
40
+ let map = await asset.getMap();
41
+ let name = `$parcel$ReactRefreshHelpers$${asset.id.slice(-4)}`;
69
42
 
70
- transform({asset, options}) {
71
- let ast = asset.ast;
72
- if (!ast || shouldExclude(asset, options)) {
73
- return [asset];
74
- }
43
+ code = `var ${name} = require(${JSON.stringify(wrapperPath)});
44
+ var prevRefreshReg = window.$RefreshReg$;
45
+ var prevRefreshSig = window.$RefreshSig$;
46
+ ${name}.prelude(module);
75
47
 
76
- let wrapperPath = path
77
- .relative(path.dirname(asset.filePath), WRAPPER)
78
- .replace(/\\/g, '/');
79
- if (!wrapperPath.startsWith('.')) {
80
- wrapperPath = './' + wrapperPath;
81
- }
48
+ try {
49
+ ${code}
50
+ ${name}.postlude(module);
51
+ } finally {
52
+ window.$RefreshReg$ = prevRefreshReg;
53
+ window.$RefreshSig$ = prevRefreshSig;
54
+ }`;
82
55
 
83
- ast.program.program.body = wrapper({
84
- helper: t.stringLiteral(wrapperPath),
85
- module: ast.program.program.body,
86
- });
87
- ast.isDirty = true;
56
+ asset.setCode(code);
57
+ if (map) {
58
+ map.offsetLines(1, 6);
59
+ asset.setMap(map);
60
+ }
88
61
 
89
62
  // The JSTransformer has already run, do it manually
90
63
  asset.addDependency({
91
- moduleSpecifier: wrapperPath,
64
+ specifier: wrapperPath,
65
+ specifierType: 'esm',
66
+ resolveFrom: __filename,
92
67
  });
93
68
 
94
69
  return [asset];
95
70
  },
96
-
97
- async generate({asset, options}) {
98
- let code = await asset.getCode();
99
- let res = {
100
- code,
101
- };
102
-
103
- let ast = asset.ast;
104
- if (ast && ast.isDirty !== false) {
105
- let sourceFileName: string = relativeUrl(
106
- options.projectRoot,
107
- asset.filePath,
108
- );
109
-
110
- let generated = generate(
111
- ast.program,
112
- {
113
- sourceMaps: options.sourceMaps,
114
- sourceFileName: sourceFileName,
115
- },
116
- code,
117
- );
118
-
119
- res.code = generated.code;
120
- // $FlowFixMe...
121
- res.map = new SourceMap(generated.rawMappings, {
122
- [sourceFileName]: null,
123
- });
124
- }
125
-
126
- if (asset.meta.globals && asset.meta.globals.size > 0) {
127
- res.code =
128
- Array.from(asset.meta.globals.values())
129
- .map(g => (g ? g.code : ''))
130
- .join('\n') +
131
- '\n' +
132
- res.code;
133
- }
134
- delete asset.meta.globals;
135
-
136
- return res;
137
- },
138
- });
71
+ }): Transformer);
@@ -2,21 +2,33 @@ var Refresh = require('react-refresh/runtime');
2
2
 
3
3
  function debounce(func, delay) {
4
4
  if (process.env.NODE_ENV === 'test') {
5
- return function(args) {
5
+ return function (args) {
6
6
  func.call(null, args);
7
7
  };
8
8
  } else {
9
- var timeout = undefined;
10
- return function(args) {
11
- clearTimeout(timeout);
12
- timeout = setTimeout(function() {
13
- timeout = undefined;
9
+ let timeout = undefined;
10
+ let lastTime = 0;
11
+ return function (args) {
12
+ // Call immediately if last call was more than the delay ago.
13
+ // Otherwise, set a timeout. This means the first call is fast
14
+ // (for the common case of a single update), and subsequent updates
15
+ // are batched.
16
+ let now = Date.now();
17
+ if (now - lastTime > delay) {
18
+ lastTime = now;
14
19
  func.call(null, args);
15
- }, delay);
20
+ } else {
21
+ clearTimeout(timeout);
22
+ timeout = setTimeout(function () {
23
+ timeout = undefined;
24
+ lastTime = Date.now();
25
+ func.call(null, args);
26
+ }, delay);
27
+ }
16
28
  };
17
29
  }
18
30
  }
19
- var enqueueUpdate = debounce(function() {
31
+ var enqueueUpdate = debounce(function () {
20
32
  Refresh.performReactRefresh();
21
33
  }, 30);
22
34
 
@@ -24,53 +36,56 @@ var enqueueUpdate = debounce(function() {
24
36
  // https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js
25
37
  // MIT License - Copyright (c) Facebook, Inc. and its affiliates.
26
38
 
27
- module.exports.prelude = function(module) {
28
- window.$RefreshReg$ = function(type, id) {
39
+ module.exports.prelude = function (module) {
40
+ window.$RefreshReg$ = function (type, id) {
29
41
  Refresh.register(type, module.id + ' ' + id);
30
42
  };
31
43
  window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform;
32
44
  };
33
45
 
34
- module.exports.postlude = function(module) {
46
+ module.exports.postlude = function (module) {
35
47
  if (isReactRefreshBoundary(module.exports)) {
36
48
  registerExportsForReactRefresh(module);
37
49
 
38
- module.hot.dispose(function(data) {
39
- data.prevExports = module.exports;
40
- });
41
-
42
- module.hot.accept(function(getParents) {
43
- var prevExports = module.hot.data.prevExports;
44
- var nextExports = module.exports;
45
- // Since we just executed the code for it, it's possible
46
- // that the new exports make it ineligible for being a boundary.
47
- var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
48
- // It can also become ineligible if its exports are incompatible
49
- // with the previous exports.
50
- // For example, if you add/remove/change exports, we'll want
51
- // to re-execute the importing modules, and force those components
52
- // to re-render. Similarly, if you convert a class component
53
- // to a function, we want to invalidate the boundary.
54
- var didInvalidate = shouldInvalidateReactRefreshBoundary(
55
- prevExports,
56
- nextExports,
57
- );
58
- if (isNoLongerABoundary || didInvalidate) {
59
- // We'll be conservative. The only case in which we won't do a full
60
- // reload is if all parent modules are also refresh boundaries.
61
- // In that case we'll add them to the current queue.
62
- var parents = getParents();
63
- if (parents.length === 0) {
64
- // Looks like we bubbled to the root. Can't recover from that.
50
+ if (module.hot) {
51
+ module.hot.dispose(function (data) {
52
+ if (Refresh.hasUnrecoverableErrors()) {
65
53
  window.location.reload();
66
- return;
67
54
  }
68
- return parents;
69
- }
70
- enqueueUpdate();
71
- });
72
- if (Refresh.hasUnrecoverableErrors()) {
73
- window.location.reload();
55
+
56
+ data.prevExports = module.exports;
57
+ });
58
+
59
+ module.hot.accept(function (getParents) {
60
+ var prevExports = module.hot.data.prevExports;
61
+ var nextExports = module.exports;
62
+ // Since we just executed the code for it, it's possible
63
+ // that the new exports make it ineligible for being a boundary.
64
+ var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
65
+ // It can also become ineligible if its exports are incompatible
66
+ // with the previous exports.
67
+ // For example, if you add/remove/change exports, we'll want
68
+ // to re-execute the importing modules, and force those components
69
+ // to re-render. Similarly, if you convert a class component
70
+ // to a function, we want to invalidate the boundary.
71
+ var didInvalidate = shouldInvalidateReactRefreshBoundary(
72
+ prevExports,
73
+ nextExports,
74
+ );
75
+ if (isNoLongerABoundary || didInvalidate) {
76
+ // We'll be conservative. The only case in which we won't do a full
77
+ // reload is if all parent modules are also refresh boundaries.
78
+ // In that case we'll add them to the current queue.
79
+ var parents = getParents();
80
+ if (parents.length === 0) {
81
+ // Looks like we bubbled to the root. Can't recover from that.
82
+ window.location.reload();
83
+ return;
84
+ }
85
+ return parents;
86
+ }
87
+ enqueueUpdate();
88
+ });
74
89
  }
75
90
  }
76
91
  };
@@ -85,14 +100,15 @@ function isReactRefreshBoundary(exports) {
85
100
  }
86
101
  var hasExports = false;
87
102
  var areAllExportsComponents = true;
103
+ let isESM = '__esModule' in exports;
88
104
  for (var key in exports) {
89
105
  hasExports = true;
90
106
  if (key === '__esModule') {
91
107
  continue;
92
108
  }
93
109
  var desc = Object.getOwnPropertyDescriptor(exports, key);
94
- if (desc && desc.get) {
95
- // Don't invoke getters as they may have side effects.
110
+ if (desc && desc.get && !isESM) {
111
+ // Don't invoke getters for CJS as they may have side effects.
96
112
  return false;
97
113
  }
98
114
  var exportValue = exports[key];
@@ -126,12 +142,14 @@ function getRefreshBoundarySignature(exports) {
126
142
  // (This is important for legacy environments.)
127
143
  return signature;
128
144
  }
145
+ let isESM = '__esModule' in exports;
129
146
  for (var key in exports) {
130
147
  if (key === '__esModule') {
131
148
  continue;
132
149
  }
133
150
  var desc = Object.getOwnPropertyDescriptor(exports, key);
134
- if (desc && desc.get) {
151
+ if (desc && desc.get && !isESM) {
152
+ // Don't invoke getters for CJS as they may have side effects.
135
153
  continue;
136
154
  }
137
155
  var exportValue = exports[key];
@@ -150,10 +168,11 @@ function registerExportsForReactRefresh(module) {
150
168
  // (This is important for legacy environments.)
151
169
  return;
152
170
  }
171
+ let isESM = '__esModule' in exports;
153
172
  for (var key in exports) {
154
173
  var desc = Object.getOwnPropertyDescriptor(exports, key);
155
- if (desc && desc.get) {
156
- // Don't invoke getters as they may have side effects.
174
+ if (desc && desc.get && !isESM) {
175
+ // Don't invoke getters for CJS as they may have side effects.
157
176
  continue;
158
177
  }
159
178
  var exportValue = exports[key];