@atlaspack/packager-js 2.14.5-canary.26 → 2.14.5-canary.262

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.
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ESMOutputFormat = void 0;
4
+ const utils_1 = require("./utils");
5
+ class ESMOutputFormat {
6
+ constructor(packager) {
7
+ this.packager = packager;
8
+ }
9
+ buildBundlePrelude() {
10
+ let res = '';
11
+ let lines = 0;
12
+ for (let [source, specifiers] of this.packager.externals) {
13
+ let defaultSpecifier = null;
14
+ let namespaceSpecifier = null;
15
+ let namedSpecifiers = [];
16
+ for (let [imported, symbol] of specifiers) {
17
+ if (imported === 'default' /* || isCommonJS*/) {
18
+ defaultSpecifier = symbol;
19
+ }
20
+ else if (imported === '*') {
21
+ namespaceSpecifier = `* as ${symbol}`;
22
+ }
23
+ else {
24
+ let specifier = imported;
25
+ if (!(0, utils_1.isValidIdentifier)(specifier)) {
26
+ specifier = JSON.stringify(specifier);
27
+ }
28
+ if (symbol !== imported) {
29
+ specifier += ` as ${symbol}`;
30
+ }
31
+ namedSpecifiers.push(specifier);
32
+ }
33
+ }
34
+ // ESModule syntax allows combining default and namespace specifiers, or default and named, but not all three.
35
+ let imported = '';
36
+ if (namespaceSpecifier) {
37
+ let s = namespaceSpecifier;
38
+ if (defaultSpecifier) {
39
+ s = `${defaultSpecifier}, ${namespaceSpecifier}`;
40
+ }
41
+ res += `import ${s} from ${JSON.stringify(source)};\n`;
42
+ lines++;
43
+ }
44
+ else if (defaultSpecifier) {
45
+ imported = defaultSpecifier;
46
+ if (namedSpecifiers.length > 0) {
47
+ imported += `, {${namedSpecifiers.join(', ')}}`;
48
+ }
49
+ }
50
+ else if (namedSpecifiers.length > 0) {
51
+ imported = `{${namedSpecifiers.join(', ')}}`;
52
+ }
53
+ if (imported.length > 0) {
54
+ res += `import ${imported} from ${JSON.stringify(source)};\n`;
55
+ lines++;
56
+ }
57
+ else if (!namespaceSpecifier) {
58
+ res += `import ${JSON.stringify(source)};\n`;
59
+ lines++;
60
+ }
61
+ }
62
+ if (res.length > 0) {
63
+ res += '\n';
64
+ lines++;
65
+ }
66
+ return [res, lines];
67
+ }
68
+ buildBundlePostlude() {
69
+ let res = '';
70
+ let lines = 0;
71
+ let exportSpecifiers = [];
72
+ for (let { asset, exportSymbol, local, exportAs, } of this.packager.exportedSymbols.values()) {
73
+ if (this.packager.wrappedAssets.has(asset)) {
74
+ let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(asset)}")`;
75
+ res += `\nvar ${local} = ${this.packager.getPropertyAccess(obj, exportSymbol)};`;
76
+ lines++;
77
+ }
78
+ for (let as of exportAs) {
79
+ let specifier = local;
80
+ if (as !== local) {
81
+ if (!(0, utils_1.isValidIdentifier)(as)) {
82
+ as = JSON.stringify(as);
83
+ }
84
+ specifier += ` as ${as}`;
85
+ }
86
+ exportSpecifiers.push(specifier);
87
+ }
88
+ }
89
+ if (exportSpecifiers.length > 0) {
90
+ res += `\nexport {${exportSpecifiers.join(', ')}};`;
91
+ lines++;
92
+ }
93
+ if (this.packager.needsPrelude &&
94
+ this.packager.shouldBundleQueue(this.packager.bundle)) {
95
+ // Should be last thing the bundle executes on intial eval
96
+ res += `\n$parcel$global.rlb(${JSON.stringify(this.packager.bundle.publicId)})`;
97
+ lines++;
98
+ }
99
+ return [res, lines];
100
+ }
101
+ }
102
+ exports.ESMOutputFormat = ESMOutputFormat;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlobalOutputFormat = void 0;
4
+ class GlobalOutputFormat {
5
+ constructor(packager) {
6
+ this.packager = packager;
7
+ }
8
+ buildBundlePrelude() {
9
+ let prelude = this.packager.bundle.env.supports('arrow-functions', true)
10
+ ? '(() => {\n'
11
+ : '(function () {\n';
12
+ return [prelude, 1];
13
+ }
14
+ buildBundlePostlude() {
15
+ return ['})();', 0];
16
+ }
17
+ }
18
+ exports.GlobalOutputFormat = GlobalOutputFormat;