@parcel/packager-js 2.0.0-beta.3 → 2.0.0-dev.1510

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.
@@ -6,7 +6,7 @@
6
6
  // anything defined in a previous bundle is accessed via the
7
7
  // orig method which is the require for previous bundles
8
8
 
9
- (function(modules, entry, mainEntry, parcelRequireName, globalName) {
9
+ (function (modules, entry, mainEntry, parcelRequireName, globalName) {
10
10
  /* eslint-disable no-undef */
11
11
  var globalObject =
12
12
  typeof globalThis !== 'undefined'
@@ -73,18 +73,20 @@
73
73
  localRequire,
74
74
  module,
75
75
  module.exports,
76
- this,
76
+ this
77
77
  );
78
78
  }
79
79
 
80
80
  return cache[name].exports;
81
81
 
82
82
  function localRequire(x) {
83
- return newRequire(localRequire.resolve(x));
83
+ var res = localRequire.resolve(x);
84
+ return res === false ? {} : newRequire(res);
84
85
  }
85
86
 
86
87
  function resolve(x) {
87
- return modules[name][1][x] || x;
88
+ var id = modules[name][1][x];
89
+ return id != null ? id : x;
88
90
  }
89
91
  }
90
92
 
@@ -99,9 +101,9 @@
99
101
  newRequire.modules = modules;
100
102
  newRequire.cache = cache;
101
103
  newRequire.parent = previousRequire;
102
- newRequire.register = function(id, exports) {
104
+ newRequire.register = function (id, exports) {
103
105
  modules[id] = [
104
- function(require, module) {
106
+ function (require, module) {
105
107
  module.exports = exports;
106
108
  },
107
109
  {},
@@ -109,7 +111,7 @@
109
111
  };
110
112
 
111
113
  Object.defineProperty(newRequire, 'root', {
112
- get: function() {
114
+ get: function () {
113
115
  return globalObject[parcelRequireName];
114
116
  },
115
117
  });
@@ -131,7 +133,7 @@
131
133
 
132
134
  // RequireJS
133
135
  } else if (typeof define === 'function' && define.amd) {
134
- define(function() {
136
+ define(function () {
135
137
  return mainExports;
136
138
  });
137
139
 
package/lib/helpers.js CHANGED
@@ -3,21 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.helpers = exports.prelude = void 0;
7
-
8
- const prelude = parcelRequireName => `var $parcel$modules = {};
6
+ exports.prelude = exports.helpers = exports.fnExpr = exports.bundleQueuePrelude = void 0;
7
+ const prelude = parcelRequireName => `
8
+ var $parcel$modules = {};
9
9
  var $parcel$inits = {};
10
10
 
11
11
  var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
12
+
12
13
  if (parcelRequire == null) {
13
14
  parcelRequire = function(id) {
14
15
  if (id in $parcel$modules) {
15
16
  return $parcel$modules[id].exports;
16
17
  }
17
18
  if (id in $parcel$inits) {
18
- let init = $parcel$inits[id];
19
+ var init = $parcel$inits[id];
19
20
  delete $parcel$inits[id];
20
- let module = {id, exports: {}};
21
+ var module = {id: id, exports: {}};
21
22
  $parcel$modules[id] = module;
22
23
  init.call(module.exports, module, module.exports);
23
24
  return module.exports;
@@ -33,17 +34,49 @@ if (parcelRequire == null) {
33
34
 
34
35
  $parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
35
36
  }
36
- `;
37
37
 
38
+ var parcelRegister = parcelRequire.register;
39
+ `;
38
40
  exports.prelude = prelude;
39
- const helpers = {
40
- $parcel$export: `function $parcel$export(e, n, v, s) {
41
+ const fnExpr = (env, params, body) => {
42
+ let block = `{ ${body.join(' ')} }`;
43
+ if (env.supports('arrow-functions')) {
44
+ return `(${params.join(', ')}) => ${block}`;
45
+ }
46
+ return `function (${params.join(', ')}) ${block}`;
47
+ };
48
+ exports.fnExpr = fnExpr;
49
+ const bundleQueuePrelude = env => `
50
+ if (!$parcel$global.lb) {
51
+ // Set of loaded bundles
52
+ $parcel$global.lb = new Set();
53
+ // Queue of bundles to execute once they're dep bundles are loaded
54
+ $parcel$global.bq = [];
55
+
56
+ // Register loaded bundle
57
+ $parcel$global.rlb = ${fnExpr(env, ['bundle'], ['$parcel$global.lb.add(bundle);', '$parcel$global.pq();'])}
58
+
59
+ // Run when ready
60
+ $parcel$global.rwr = ${fnExpr(env,
61
+ // b = bundle public id
62
+ // r = run function to execute the bundle entry
63
+ // d = list of dependent bundles this bundle requires before executing
64
+ ['b', 'r', 'd'], ['$parcel$global.bq.push({b, r, d});', '$parcel$global.pq();'])}
65
+
66
+ // Process queue
67
+ $parcel$global.pq = ${fnExpr(env, [], [`var runnableEntry = $parcel$global.bq.find(${fnExpr(env, ['i'], [`return i.d.every(${fnExpr(env, ['dep'], ['return $parcel$global.lb.has(dep);'])});`])});`, 'if (runnableEntry) {', `$parcel$global.bq = $parcel$global.bq.filter(${fnExpr(env, ['i'], ['return i.b !== runnableEntry.b;'])});`, 'runnableEntry.r();', '$parcel$global.pq();', '}'])}
68
+ }
69
+ `;
70
+ exports.bundleQueuePrelude = bundleQueuePrelude;
71
+ const $parcel$export = `
72
+ function $parcel$export(e, n, v, s) {
41
73
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
42
74
  }
43
- `,
44
- $parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
75
+ `;
76
+ const $parcel$exportWildcard = `
77
+ function $parcel$exportWildcard(dest, source) {
45
78
  Object.keys(source).forEach(function(key) {
46
- if (key === 'default' || key === '__esModule') {
79
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
47
80
  return;
48
81
  }
49
82
 
@@ -51,31 +84,46 @@ const helpers = {
51
84
  enumerable: true,
52
85
  get: function get() {
53
86
  return source[key];
54
- },
87
+ }
55
88
  });
56
89
  });
57
90
 
58
91
  return dest;
59
92
  }
60
- `,
61
- $parcel$interopDefault: `function $parcel$interopDefault(a) {
93
+ `;
94
+ const $parcel$interopDefault = `
95
+ function $parcel$interopDefault(a) {
62
96
  return a && a.__esModule ? a.default : a;
63
97
  }
64
- `,
65
- $parcel$global: `var $parcel$global =
66
- typeof globalThis !== 'undefined'
67
- ? globalThis
68
- : typeof self !== 'undefined'
69
- ? self
70
- : typeof window !== 'undefined'
71
- ? window
72
- : typeof global !== 'undefined'
73
- ? global
74
- : {};
75
- `,
76
- $parcel$defineInteropFlag: `function $parcel$defineInteropFlag(a) {
98
+ `;
99
+ const $parcel$global = env => {
100
+ if (env.supports('global-this')) {
101
+ return `
102
+ var $parcel$global = globalThis;
103
+ `;
104
+ }
105
+ return `
106
+ var $parcel$global =
107
+ typeof globalThis !== 'undefined'
108
+ ? globalThis
109
+ : typeof self !== 'undefined'
110
+ ? self
111
+ : typeof window !== 'undefined'
112
+ ? window
113
+ : typeof global !== 'undefined'
114
+ ? global
115
+ : {};
116
+ `;
117
+ };
118
+ const $parcel$defineInteropFlag = `
119
+ function $parcel$defineInteropFlag(a) {
77
120
  Object.defineProperty(a, '__esModule', {value: true, configurable: true});
78
121
  }
79
- `
80
- };
81
- exports.helpers = helpers;
122
+ `;
123
+ const helpers = exports.helpers = {
124
+ $parcel$export,
125
+ $parcel$exportWildcard,
126
+ $parcel$interopDefault,
127
+ $parcel$global,
128
+ $parcel$defineInteropFlag
129
+ };
package/lib/index.js CHANGED
@@ -4,87 +4,84 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _plugin() {
9
8
  const data = require("@parcel/plugin");
10
-
11
9
  _plugin = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _utils() {
19
15
  const data = require("@parcel/utils");
20
-
21
16
  _utils = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
- function _path() {
29
- const data = _interopRequireDefault(require("path"));
30
-
31
- _path = function () {
21
+ function _diagnostic() {
22
+ const data = require("@parcel/diagnostic");
23
+ _diagnostic = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
- function _nullthrows() {
39
- const data = _interopRequireDefault(require("nullthrows"));
40
-
41
- _nullthrows = function () {
28
+ function _rust() {
29
+ const data = require("@parcel/rust");
30
+ _rust = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
- function _DevPackager() {
49
- const data = require("./DevPackager");
50
-
51
- _DevPackager = function () {
35
+ function _path() {
36
+ const data = _interopRequireDefault(require("path"));
37
+ _path = function () {
52
38
  return data;
53
39
  };
54
-
55
40
  return data;
56
41
  }
57
-
58
- function _ScopeHoistingPackager() {
59
- const data = require("./ScopeHoistingPackager");
60
-
61
- _ScopeHoistingPackager = function () {
42
+ function _nullthrows() {
43
+ const data = _interopRequireDefault(require("nullthrows"));
44
+ _nullthrows = function () {
62
45
  return data;
63
46
  };
64
-
65
47
  return data;
66
48
  }
67
-
49
+ var _DevPackager = require("./DevPackager");
50
+ var _ScopeHoistingPackager = require("./ScopeHoistingPackager");
68
51
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
-
70
- var _default = new (_plugin().Packager)({
52
+ const CONFIG_SCHEMA = {
53
+ type: 'object',
54
+ properties: {
55
+ unstable_asyncBundleRuntime: {
56
+ type: 'boolean'
57
+ }
58
+ },
59
+ additionalProperties: false
60
+ };
61
+ var _default = exports.default = new (_plugin().Packager)({
71
62
  async loadConfig({
63
+ config,
72
64
  options
73
65
  }) {
74
- var _pkg$config$name, _pkg$files;
75
-
66
+ var _pkg$contents$name, _pkg$contents, _pkg$contents$package;
76
67
  // Generate a name for the global parcelRequire function that is unique to this project.
77
68
  // This allows multiple parcel builds to coexist on the same page.
78
- let pkg = await (0, _utils().loadConfig)(options.inputFS, _path().default.join(options.entryRoot, 'index'), ['package.json'], options.projectRoot);
79
- let name = (_pkg$config$name = pkg === null || pkg === void 0 ? void 0 : pkg.config.name) !== null && _pkg$config$name !== void 0 ? _pkg$config$name : '';
69
+ let pkg = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['package.json']);
70
+ let packageKey = '@parcel/packager-js';
71
+ if (pkg !== null && pkg !== void 0 && pkg.contents[packageKey]) {
72
+ _utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
73
+ data: pkg === null || pkg === void 0 ? void 0 : pkg.contents[packageKey],
74
+ source: await options.inputFS.readFile(pkg.filePath, 'utf8'),
75
+ filePath: pkg.filePath,
76
+ prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
77
+ }, packageKey, `Invalid config for ${packageKey}`);
78
+ }
79
+ let name = (_pkg$contents$name = pkg === null || pkg === void 0 || (_pkg$contents = pkg.contents) === null || _pkg$contents === void 0 ? void 0 : _pkg$contents.name) !== null && _pkg$contents$name !== void 0 ? _pkg$contents$name : '';
80
80
  return {
81
- config: {
82
- parcelRequireName: 'parcelRequire' + (0, _utils().md5FromString)(name).slice(-4)
83
- },
84
- files: (_pkg$files = pkg === null || pkg === void 0 ? void 0 : pkg.files) !== null && _pkg$files !== void 0 ? _pkg$files : []
81
+ parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
82
+ unstable_asyncBundleRuntime: Boolean(pkg === null || pkg === void 0 || (_pkg$contents$package = pkg.contents[packageKey]) === null || _pkg$contents$package === void 0 ? void 0 : _pkg$contents$package.unstable_asyncBundleRuntime)
85
83
  };
86
84
  },
87
-
88
85
  async package({
89
86
  bundle,
90
87
  bundleGraph,
@@ -93,12 +90,39 @@ var _default = new (_plugin().Packager)({
93
90
  config,
94
91
  options
95
92
  }) {
96
- let packager = bundle.env.shouldScopeHoist ? new (_ScopeHoistingPackager().ScopeHoistingPackager)(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName) : new (_DevPackager().DevPackager)(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
97
- let {
98
- contents,
99
- map
100
- } = await packager.package();
93
+ // If this is a non-module script, and there is only one asset with no dependencies,
94
+ // then we don't need to package at all and can pass through the original code un-wrapped.
95
+ let contents, map;
96
+ if (bundle.env.sourceType === 'script') {
97
+ let entries = bundle.getEntryAssets();
98
+ if (entries.length === 1 && bundleGraph.getDependencies(entries[0]).length === 0) {
99
+ contents = await entries[0].getCode();
100
+ map = await entries[0].getMap();
101
+ }
102
+ }
103
+ if (contents == null) {
104
+ let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
105
+ ({
106
+ contents,
107
+ map
108
+ } = await packager.package());
109
+ }
101
110
  contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
111
+
112
+ // For library builds, we need to replace URL references with their final resolved paths.
113
+ // For non-library builds, this is handled in the JS runtime.
114
+ if (bundle.env.isLibrary) {
115
+ ({
116
+ contents,
117
+ map
118
+ } = (0, _utils().replaceURLReferences)({
119
+ bundle,
120
+ bundleGraph,
121
+ contents,
122
+ map,
123
+ getReplacement: s => JSON.stringify(s).slice(1, -1)
124
+ }));
125
+ }
102
126
  return (0, _utils().replaceInlineReferences)({
103
127
  bundle,
104
128
  bundleGraph,
@@ -111,14 +135,9 @@ var _default = new (_plugin().Packager)({
111
135
  map
112
136
  });
113
137
  }
114
-
115
138
  });
116
-
117
- exports.default = _default;
118
-
119
139
  async function getSourceMapSuffix(getSourceMapReference, map) {
120
140
  let sourcemapReference = await getSourceMapReference(map);
121
-
122
141
  if (sourcemapReference != null) {
123
142
  return '//# sourceMappingURL=' + sourcemapReference + '\n';
124
143
  } else {
package/lib/utils.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSpecifier = getSpecifier;
7
+ exports.replaceScriptDependencies = replaceScriptDependencies;
8
+ function _nullthrows() {
9
+ const data = _interopRequireDefault(require("nullthrows"));
10
+ _nullthrows = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ // This replaces __parcel__require__ references left by the transformer with
17
+ // parcelRequire calls of the resolved asset id. This lets runtimes work within
18
+ // script bundles, which must be outside the bundle wrapper so their variables are global.
19
+ function replaceScriptDependencies(bundleGraph, bundle, code, map, parcelRequireName) {
20
+ let entry = (0, _nullthrows().default)(bundle.getMainEntry());
21
+ let dependencies = bundleGraph.getDependencies(entry);
22
+ let lineCount = 0;
23
+ let offset = 0;
24
+ let columnStartIndex = 0;
25
+ code = code.replace(/\n|__parcel__require__\(['"](.*?)['"]\)/g, (m, s, i) => {
26
+ if (m === '\n') {
27
+ columnStartIndex = i + offset + 1;
28
+ lineCount++;
29
+ return '\n';
30
+ }
31
+ let dep = (0, _nullthrows().default)(dependencies.find(d => getSpecifier(d) === s));
32
+ let resolved = (0, _nullthrows().default)(bundleGraph.getResolvedAsset(dep, bundle));
33
+ let publicId = bundleGraph.getAssetPublicId(resolved);
34
+ let replacement = `${parcelRequireName}("${publicId}")`;
35
+ if (map) {
36
+ let lengthDifference = replacement.length - m.length;
37
+ if (lengthDifference !== 0) {
38
+ map.offsetColumns(lineCount + 1, i + offset - columnStartIndex + m.length, lengthDifference);
39
+ offset += lengthDifference;
40
+ }
41
+ }
42
+ return replacement;
43
+ });
44
+ return code;
45
+ }
46
+ function getSpecifier(dep) {
47
+ if (typeof dep.meta.placeholder === 'string') {
48
+ return dep.meta.placeholder;
49
+ }
50
+ return dep.specifier;
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/packager-js",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-dev.1510+a9bb85adf",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,15 +17,17 @@
17
17
  "source": "src/index.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "^2.0.0-beta.1"
20
+ "parcel": "^2.0.0-dev.1508+a9bb85adf"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.0.0-beta.3",
24
- "@parcel/plugin": "2.0.0-beta.3",
25
- "@parcel/source-map": "2.0.0-rc.1.0",
26
- "@parcel/utils": "2.0.0-beta.3",
23
+ "@parcel/diagnostic": "2.0.0-dev.1510+a9bb85adf",
24
+ "@parcel/plugin": "2.0.0-dev.1510+a9bb85adf",
25
+ "@parcel/rust": "2.11.1-dev.3133+a9bb85adf",
26
+ "@parcel/source-map": "^2.1.1",
27
+ "@parcel/types": "2.0.0-dev.1510+a9bb85adf",
28
+ "@parcel/utils": "2.0.0-dev.1510+a9bb85adf",
27
29
  "globals": "^13.2.0",
28
30
  "nullthrows": "^1.1.1"
29
31
  },
30
- "gitHead": "bf03f018093f8c7ca4c3a544524e15065a637b3b"
32
+ "gitHead": "a9bb85adf8f3b38631e178b3aacaa30c78696e36"
31
33
  }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@parcel/eslint-config",
3
+ "overrides": [
4
+ {
5
+ "files": ["dev-prelude.js"],
6
+ "parser": "espree",
7
+ "parserOptions": {
8
+ "ecmaVersion": 5,
9
+ "sourceType": "script"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -4,19 +4,6 @@ import type {
4
4
  OutputFormat,
5
5
  } from './ScopeHoistingPackager';
6
6
 
7
- // List of engines that support object destructuring syntax
8
- const DESTRUCTURING_ENGINES = {
9
- chrome: '51',
10
- edge: '15',
11
- firefox: '53',
12
- safari: '10',
13
- node: '6.5',
14
- ios: '10',
15
- samsung: '5',
16
- opera: '38',
17
- electron: '1.2',
18
- };
19
-
20
7
  export class CJSOutputFormat implements OutputFormat {
21
8
  packager: ScopeHoistingPackager;
22
9
 
@@ -29,70 +16,12 @@ export class CJSOutputFormat implements OutputFormat {
29
16
  let lines = 0;
30
17
 
31
18
  for (let [source, specifiers] of this.packager.externals) {
32
- let properties = [];
33
- let categories = new Set();
34
- for (let [imported, symbol] of specifiers) {
35
- if (imported === '*') {
36
- categories.add('namespace');
37
- } else if (imported === 'default') {
38
- categories.add('default');
39
- } else {
40
- categories.add('named');
41
- properties.push({
42
- key: imported,
43
- value: symbol,
44
- });
45
- }
46
- }
47
-
48
- let specifiersWildcard = specifiers.get('*');
49
- let specifiersDefault = specifiers.get('default');
50
-
51
- // Attempt to combine require calls as much as possible. Namespace, default, and named specifiers
52
- // cannot be combined, so in the case where we have more than one type, assign the require() result
53
- // to a variable first and then create additional variables for each specifier based on that.
54
- // Otherwise, if just one category is imported, just assign and require all at once.
55
- if (categories.size > 1) {
56
- let name = specifiersWildcard || this.packager.getTopLevelName(source);
57
- res += `var ${name} = require(${JSON.stringify(source)});\n`;
58
- lines++;
59
-
60
- if (specifiersDefault) {
61
- res += `var ${specifiersDefault} = $parcel$interopDefault(${name});\n`;
62
- lines++;
63
- this.packager.usedHelpers.add('$parcel$interopDefault');
64
- }
65
-
66
- if (properties.length > 0) {
67
- let [r, l] = this.generateDestructuringAssignment(
68
- properties,
69
- name,
70
- true,
71
- );
72
-
73
- res += r;
74
- lines += l;
75
- }
76
- } else if (specifiersDefault) {
77
- res += `var ${specifiersDefault} = $parcel$interopDefault(require(${JSON.stringify(
78
- source,
79
- )}));\n`;
80
- lines++;
81
- this.packager.usedHelpers.add('$parcel$interopDefault');
82
- } else if (specifiersWildcard) {
83
- res += `var ${specifiersWildcard} = require(${JSON.stringify(
84
- source,
85
- )});\n`;
19
+ // CJS only supports the namespace symbol. This ensures that all accesses
20
+ // are live and the `this` binding is correct.
21
+ let namespace = specifiers.get('*');
22
+ if (namespace) {
23
+ res += `var ${namespace} = require(${JSON.stringify(source)});\n`;
86
24
  lines++;
87
- } else if (properties.length > 0) {
88
- let [r, l] = this.generateDestructuringAssignment(
89
- properties,
90
- `require(${JSON.stringify(source)})`,
91
- false,
92
- );
93
-
94
- res += r;
95
- lines += l;
96
25
  } else {
97
26
  res += `require(${JSON.stringify(source)});\n`;
98
27
  lines++;
@@ -107,48 +36,7 @@ export class CJSOutputFormat implements OutputFormat {
107
36
  return [res, lines];
108
37
  }
109
38
 
110
- generateDestructuringAssignment(
111
- specifiers: Array<{|key: string, value: string|}>,
112
- value: string,
113
- isIdentifier: boolean,
114
- ): [string, number] {
115
- let res = '';
116
- let lines = 0;
117
-
118
- // If destructuring is not supported, generate a series of variable declarations
119
- // with member expressions for each property.
120
- if (!this.packager.bundle.env.matchesEngines(DESTRUCTURING_ENGINES)) {
121
- if (!isIdentifier && specifiers.length > 1) {
122
- let name = this.packager.getTopLevelName('temp');
123
- res += `var ${name} = ${value};\n`;
124
- lines++;
125
- value = name;
126
- }
127
-
128
- for (let specifier of specifiers) {
129
- res += `var ${specifier.value} = ${value}.${specifier.key};\n`;
130
- lines++;
131
- }
132
-
133
- return [res, lines];
134
- }
135
-
136
- let s = specifiers.map(specifier => {
137
- let s = specifier.key;
138
- if (specifier.value !== specifier.key) {
139
- s += `: ${specifier.value}`;
140
- }
141
-
142
- return s;
143
- });
144
-
145
- res += `var {${s.join(', ')}} = ${value};\n`;
146
- lines++;
147
-
148
- return [res, lines];
149
- }
150
-
151
- buildBundlePostlude(): string {
152
- return '';
39
+ buildBundlePostlude(): [string, number] {
40
+ return ['', 0];
153
41
  }
154
42
  }