@module-federation/esbuild 0.0.95 → 0.0.97

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 (61) hide show
  1. package/dist/adapters/lib/collect-exports.js +151 -0
  2. package/dist/adapters/lib/collect-exports.mjs +87 -0
  3. package/dist/adapters/lib/commonjs.js +260 -0
  4. package/dist/adapters/lib/commonjs.mjs +209 -0
  5. package/dist/adapters/lib/containerPlugin.js +232 -0
  6. package/dist/adapters/lib/containerPlugin.mjs +182 -0
  7. package/dist/adapters/lib/containerReference.js +219 -0
  8. package/dist/adapters/lib/containerReference.mjs +154 -0
  9. package/dist/adapters/lib/lexer.js +184 -0
  10. package/dist/adapters/lib/lexer.mjs +138 -0
  11. package/dist/adapters/lib/linkRemotesPlugin.js +115 -0
  12. package/dist/adapters/lib/linkRemotesPlugin.mjs +50 -0
  13. package/dist/adapters/lib/manifest.js +229 -0
  14. package/dist/adapters/lib/manifest.mjs +168 -0
  15. package/dist/adapters/lib/plugin.js +339 -0
  16. package/dist/adapters/lib/plugin.mjs +282 -0
  17. package/dist/adapters/lib/react-replacements.js +81 -0
  18. package/dist/adapters/lib/react-replacements.mjs +35 -0
  19. package/dist/adapters/lib/transform.js +169 -0
  20. package/dist/adapters/lib/transform.mjs +120 -0
  21. package/dist/adapters/lib/utils.js +83 -0
  22. package/dist/adapters/lib/utils.mjs +33 -0
  23. package/dist/build.js +131 -473
  24. package/dist/build.mjs +13 -380
  25. package/dist/index.js +41 -26
  26. package/dist/index.mjs +4 -1
  27. package/dist/lib/config/configuration-context.js +70 -0
  28. package/dist/lib/config/configuration-context.mjs +20 -0
  29. package/dist/lib/config/federation-config.js +31 -0
  30. package/dist/lib/config/federation-config.mjs +4 -0
  31. package/dist/lib/config/share-utils.js +339 -0
  32. package/dist/lib/config/share-utils.mjs +254 -0
  33. package/dist/lib/config/with-native-federation.js +118 -0
  34. package/dist/lib/config/with-native-federation.mjs +71 -0
  35. package/dist/lib/core/build-adapter.js +70 -0
  36. package/dist/lib/core/build-adapter.mjs +18 -0
  37. package/dist/lib/core/createContainerTemplate.js +231 -0
  38. package/dist/lib/core/createContainerTemplate.mjs +185 -0
  39. package/dist/lib/core/default-skip-list.js +99 -0
  40. package/dist/lib/core/default-skip-list.mjs +47 -0
  41. package/dist/lib/core/federation-options.js +31 -0
  42. package/dist/lib/core/federation-options.mjs +4 -0
  43. package/dist/lib/core/get-externals.js +65 -0
  44. package/dist/lib/core/get-externals.mjs +19 -0
  45. package/dist/lib/core/load-federation-config.js +69 -0
  46. package/dist/lib/core/load-federation-config.mjs +20 -0
  47. package/dist/lib/core/write-federation-info.js +65 -0
  48. package/dist/lib/core/write-federation-info.mjs +16 -0
  49. package/dist/lib/utils/logger.js +111 -0
  50. package/dist/lib/utils/logger.mjs +46 -0
  51. package/dist/lib/utils/mapped-paths.js +94 -0
  52. package/dist/lib/utils/mapped-paths.mjs +46 -0
  53. package/dist/lib/utils/normalize.js +63 -0
  54. package/dist/lib/utils/normalize.mjs +17 -0
  55. package/dist/lib/utils/package-info.js +324 -0
  56. package/dist/lib/utils/package-info.mjs +265 -0
  57. package/dist/plugin.d.ts +1 -0
  58. package/dist/plugin.js +79 -1231
  59. package/dist/plugin.mjs +2 -1187
  60. package/dist/resolve/esm-resolver.mjs +15 -22
  61. package/package.json +2 -2
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ /************************************************************************/
13
+ // webpack/runtime/compat_get_default_export
14
+ (() => {
15
+ // getDefaultExport function for compatibility with non-ESM modules
16
+ __webpack_require__.n = (module) => {
17
+ var getter = module && module.__esModule ?
18
+ () => (module['default']) :
19
+ () => (module);
20
+ __webpack_require__.d(getter, { a: getter });
21
+ return getter;
22
+ };
23
+
24
+ })();
25
+ // webpack/runtime/define_property_getters
26
+ (() => {
27
+ __webpack_require__.d = (exports, definition) => {
28
+ for(var key in definition) {
29
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ })();
35
+ // webpack/runtime/has_own_property
36
+ (() => {
37
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
38
+ })();
39
+ // webpack/runtime/make_namespace_object
40
+ (() => {
41
+ // define __esModule on exports
42
+ __webpack_require__.r = (exports) => {
43
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
44
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45
+ }
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ };
48
+ })();
49
+ /************************************************************************/
50
+ var __webpack_exports__ = {};
51
+ // ESM COMPAT FLAG
52
+ __webpack_require__.r(__webpack_exports__);
53
+
54
+ // EXPORTS
55
+ __webpack_require__.d(__webpack_exports__, {
56
+ buildFederationHost: () => (/* binding */ buildFederationHost),
57
+ initializeHostPlugin: () => (/* binding */ initializeHostPlugin)
58
+ });
59
+
60
+ ;// CONCATENATED MODULE: external "fs"
61
+ const external_fs_namespaceObject = require("fs");
62
+ var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject);
63
+ ;// CONCATENATED MODULE: ./src/adapters/lib/containerReference.ts
64
+
65
+ // Builds the federation host code
66
+ const buildFederationHost = (config)=>{
67
+ const { name, remotes, shared } = config;
68
+ const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
69
+ name: remoteAlias,
70
+ entry: remote,
71
+ alias: remoteAlias,
72
+ type: 'esm'
73
+ }))) : '[]';
74
+ const sharedConfig = Object.entries(shared ?? {}).reduce((acc, [pkg, config])=>{
75
+ var _config_requiredVersion;
76
+ const version = ((_config_requiredVersion = config.requiredVersion) === null || _config_requiredVersion === void 0 ? void 0 : _config_requiredVersion.replace(/^[^0-9]/, '')) || '';
77
+ acc += `${JSON.stringify(pkg)}: {
78
+ "package": "${pkg}",
79
+ "version": "${version}",
80
+ "scope": "default",
81
+ "get": async () => await import('federationShare/${pkg}'),
82
+ "shareConfig": {
83
+ "singleton": ${config.singleton},
84
+ "requiredVersion": "${config.requiredVersion}",
85
+ "eager": ${config.eager},
86
+ "strictVersion": ${config.strictVersion}
87
+ }
88
+ },\n`;
89
+ return acc;
90
+ }, '{') + '}';
91
+ return `
92
+ import { init as initFederationHost } from "@module-federation/runtime";
93
+
94
+ const createVirtualRemoteModule = (name, ref, exports) => {
95
+ const genExports = exports.map(e =>
96
+ e === 'default'
97
+ ? 'export default mfLsZJ92.default;'
98
+ : \`export const \${e} = mfLsZJ92[\${JSON.stringify(e)}];\`
99
+ ).join('');
100
+
101
+ const loadRef = \`const mfLsZJ92 = await container.loadRemote(\${JSON.stringify(ref)});\`;
102
+
103
+ return \`
104
+ const container = __FEDERATION__.__INSTANCES__.find(container => container.name === name) || __FEDERATION__.__INSTANCES__[0];
105
+ \${loadRef}
106
+ \${genExports}
107
+ \`;
108
+ };
109
+
110
+ function encodeInlineESM(code) {
111
+ return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(code);
112
+ }
113
+
114
+ const runtimePlugin = () => ({
115
+ name: 'import-maps-plugin',
116
+ async init(args) {
117
+ const remotePrefetch = args.options.remotes.map(async (remote) => {
118
+ console.log('remote', remote);
119
+ if (remote.type === 'esm') {
120
+ await import(remote.entry);
121
+ }
122
+ });
123
+
124
+ await Promise.all(remotePrefetch);
125
+ if (typeof moduleMap !== 'undefined') {
126
+ const map = Object.keys(moduleMap).reduce((acc, expose) => {
127
+ const importMap = importShim.getImportMap().imports;
128
+ const key = args.origin.name + expose.replace('.', '');
129
+ if (!importMap[key]) {
130
+ const encodedModule = encodeInlineESM(
131
+ createVirtualRemoteModule(args.origin.name, key, moduleMap[expose].exports)
132
+ );
133
+ acc[key] = encodedModule;
134
+ }
135
+ return acc;
136
+ }, {});
137
+
138
+ await importShim.addImportMap({ imports: map });
139
+ }
140
+
141
+ return args;
142
+ }
143
+ });
144
+
145
+ const mfHoZJ92 = initFederationHost({
146
+ name: ${JSON.stringify(name)},
147
+ remotes: ${remoteConfigs},
148
+ shared: ${sharedConfig},
149
+ plugins: [runtimePlugin()],
150
+ });
151
+
152
+ await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
153
+
154
+
155
+ `;
156
+ };
157
+ const initializeHostPlugin = (config)=>({
158
+ name: 'host-initialization',
159
+ setup (build) {
160
+ build.onResolve({
161
+ filter: /federation-host/
162
+ }, (args)=>({
163
+ path: args.path,
164
+ namespace: 'federation-host',
165
+ pluginData: {
166
+ kind: args.kind,
167
+ resolveDir: args.resolveDir
168
+ }
169
+ }));
170
+ build.onLoad({
171
+ filter: /.*/,
172
+ namespace: 'federation-host'
173
+ }, async (args)=>({
174
+ contents: buildFederationHost(config),
175
+ resolveDir: args.pluginData.resolveDir
176
+ }));
177
+ // Add custom loaders
178
+ const loaders = build.initialOptions.loader || {};
179
+ // Apply custom loaders
180
+ for (const [ext, loader] of Object.entries(loaders)){
181
+ build.onLoad({
182
+ filter: new RegExp(`\\${ext}$`),
183
+ namespace: 'file'
184
+ }, async (args)=>{
185
+ const contents = await external_fs_default().promises.readFile(args.path, 'utf8');
186
+ return {
187
+ contents: buildFederationHost(config) + contents,
188
+ loader
189
+ };
190
+ });
191
+ }
192
+ // Fallback loader for files not matched by custom loaders
193
+ const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
194
+ build.onLoad({
195
+ filter: /.*\.(ts|js|mjs)$/,
196
+ namespace: 'file'
197
+ }, //@ts-ignore
198
+ async (args)=>{
199
+ if (!fallbackFilter.test(args.path)) {
200
+ if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
201
+ return;
202
+ }
203
+ const contents = await external_fs_default().promises.readFile(args.path, 'utf8');
204
+ return {
205
+ contents: 'import "federation-host"; \n ' + contents
206
+ };
207
+ }
208
+ });
209
+ }
210
+ });
211
+
212
+ exports.buildFederationHost = __webpack_exports__.buildFederationHost;
213
+ exports.initializeHostPlugin = __webpack_exports__.initializeHostPlugin;
214
+ for(var __webpack_i__ in __webpack_exports__) {
215
+ if(["buildFederationHost","initializeHostPlugin"].indexOf(__webpack_i__) === -1) {
216
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
217
+ }
218
+ }
219
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,154 @@
1
+ import fs from "fs";
2
+
3
+ ;// CONCATENATED MODULE: external "fs"
4
+
5
+ ;// CONCATENATED MODULE: ./src/adapters/lib/containerReference.ts
6
+
7
+ // Builds the federation host code
8
+ const buildFederationHost = (config)=>{
9
+ const { name, remotes, shared } = config;
10
+ const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
11
+ name: remoteAlias,
12
+ entry: remote,
13
+ alias: remoteAlias,
14
+ type: 'esm'
15
+ }))) : '[]';
16
+ const sharedConfig = Object.entries(shared ?? {}).reduce((acc, [pkg, config])=>{
17
+ var _config_requiredVersion;
18
+ const version = ((_config_requiredVersion = config.requiredVersion) === null || _config_requiredVersion === void 0 ? void 0 : _config_requiredVersion.replace(/^[^0-9]/, '')) || '';
19
+ acc += `${JSON.stringify(pkg)}: {
20
+ "package": "${pkg}",
21
+ "version": "${version}",
22
+ "scope": "default",
23
+ "get": async () => await import('federationShare/${pkg}'),
24
+ "shareConfig": {
25
+ "singleton": ${config.singleton},
26
+ "requiredVersion": "${config.requiredVersion}",
27
+ "eager": ${config.eager},
28
+ "strictVersion": ${config.strictVersion}
29
+ }
30
+ },\n`;
31
+ return acc;
32
+ }, '{') + '}';
33
+ return `
34
+ import { init as initFederationHost } from "@module-federation/runtime";
35
+
36
+ const createVirtualRemoteModule = (name, ref, exports) => {
37
+ const genExports = exports.map(e =>
38
+ e === 'default'
39
+ ? 'export default mfLsZJ92.default;'
40
+ : \`export const \${e} = mfLsZJ92[\${JSON.stringify(e)}];\`
41
+ ).join('');
42
+
43
+ const loadRef = \`const mfLsZJ92 = await container.loadRemote(\${JSON.stringify(ref)});\`;
44
+
45
+ return \`
46
+ const container = __FEDERATION__.__INSTANCES__.find(container => container.name === name) || __FEDERATION__.__INSTANCES__[0];
47
+ \${loadRef}
48
+ \${genExports}
49
+ \`;
50
+ };
51
+
52
+ function encodeInlineESM(code) {
53
+ return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(code);
54
+ }
55
+
56
+ const runtimePlugin = () => ({
57
+ name: 'import-maps-plugin',
58
+ async init(args) {
59
+ const remotePrefetch = args.options.remotes.map(async (remote) => {
60
+ console.log('remote', remote);
61
+ if (remote.type === 'esm') {
62
+ await import(remote.entry);
63
+ }
64
+ });
65
+
66
+ await Promise.all(remotePrefetch);
67
+ if (typeof moduleMap !== 'undefined') {
68
+ const map = Object.keys(moduleMap).reduce((acc, expose) => {
69
+ const importMap = importShim.getImportMap().imports;
70
+ const key = args.origin.name + expose.replace('.', '');
71
+ if (!importMap[key]) {
72
+ const encodedModule = encodeInlineESM(
73
+ createVirtualRemoteModule(args.origin.name, key, moduleMap[expose].exports)
74
+ );
75
+ acc[key] = encodedModule;
76
+ }
77
+ return acc;
78
+ }, {});
79
+
80
+ await importShim.addImportMap({ imports: map });
81
+ }
82
+
83
+ return args;
84
+ }
85
+ });
86
+
87
+ const mfHoZJ92 = initFederationHost({
88
+ name: ${JSON.stringify(name)},
89
+ remotes: ${remoteConfigs},
90
+ shared: ${sharedConfig},
91
+ plugins: [runtimePlugin()],
92
+ });
93
+
94
+ await Promise.all(mfHoZJ92.initializeSharing('default', 'version-first'));
95
+
96
+
97
+ `;
98
+ };
99
+ const initializeHostPlugin = (config)=>({
100
+ name: 'host-initialization',
101
+ setup (build) {
102
+ build.onResolve({
103
+ filter: /federation-host/
104
+ }, (args)=>({
105
+ path: args.path,
106
+ namespace: 'federation-host',
107
+ pluginData: {
108
+ kind: args.kind,
109
+ resolveDir: args.resolveDir
110
+ }
111
+ }));
112
+ build.onLoad({
113
+ filter: /.*/,
114
+ namespace: 'federation-host'
115
+ }, async (args)=>({
116
+ contents: buildFederationHost(config),
117
+ resolveDir: args.pluginData.resolveDir
118
+ }));
119
+ // Add custom loaders
120
+ const loaders = build.initialOptions.loader || {};
121
+ // Apply custom loaders
122
+ for (const [ext, loader] of Object.entries(loaders)){
123
+ build.onLoad({
124
+ filter: new RegExp(`\\${ext}$`),
125
+ namespace: 'file'
126
+ }, async (args)=>{
127
+ const contents = await fs.promises.readFile(args.path, 'utf8');
128
+ return {
129
+ contents: buildFederationHost(config) + contents,
130
+ loader
131
+ };
132
+ });
133
+ }
134
+ // Fallback loader for files not matched by custom loaders
135
+ const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
136
+ build.onLoad({
137
+ filter: /.*\.(ts|js|mjs)$/,
138
+ namespace: 'file'
139
+ }, //@ts-ignore
140
+ async (args)=>{
141
+ if (!fallbackFilter.test(args.path)) {
142
+ if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) {
143
+ return;
144
+ }
145
+ const contents = await fs.promises.readFile(args.path, 'utf8');
146
+ return {
147
+ contents: 'import "federation-host"; \n ' + contents
148
+ };
149
+ }
150
+ });
151
+ }
152
+ });
153
+
154
+ export { buildFederationHost, initializeHostPlugin };
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ /************************************************************************/
13
+ // webpack/runtime/define_property_getters
14
+ (() => {
15
+ __webpack_require__.d = (exports, definition) => {
16
+ for(var key in definition) {
17
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
18
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
19
+ }
20
+ }
21
+ };
22
+ })();
23
+ // webpack/runtime/has_own_property
24
+ (() => {
25
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
26
+ })();
27
+ // webpack/runtime/make_namespace_object
28
+ (() => {
29
+ // define __esModule on exports
30
+ __webpack_require__.r = (exports) => {
31
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
32
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
33
+ }
34
+ Object.defineProperty(exports, '__esModule', { value: true });
35
+ };
36
+ })();
37
+ /************************************************************************/
38
+ var __webpack_exports__ = {};
39
+ __webpack_require__.r(__webpack_exports__);
40
+ __webpack_require__.d(__webpack_exports__, {
41
+ Lexer: () => (Lexer)
42
+ });
43
+ // simplified from acorn (MIT license)
44
+ function isNewLine(code) {
45
+ return code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
46
+ }
47
+ function codePointToString(ch) {
48
+ if (ch <= 0xffff) return String.fromCharCode(ch);
49
+ ch -= 0x10000;
50
+ return String.fromCharCode((ch >> 10) + 0xd800, (ch & 0x03ff) + 0xdc00);
51
+ }
52
+ class Lexer {
53
+ readString(input, pos) {
54
+ if (pos >= input.length) return null;
55
+ this.input = input;
56
+ this.pos = pos;
57
+ const quote = this.input.charCodeAt(pos);
58
+ if (!(quote === 34 || quote === 39)) return null;
59
+ let out = '';
60
+ let chunkStart = ++this.pos;
61
+ //eslint-disable-next-line no-constant-condition
62
+ while(true){
63
+ if (this.pos >= this.input.length) return null;
64
+ const ch = this.input.charCodeAt(this.pos);
65
+ if (ch === quote) break;
66
+ if (ch === 92) {
67
+ out += this.input.slice(chunkStart, this.pos);
68
+ const escaped = this.readEscapedChar();
69
+ if (escaped === null) return null;
70
+ out += escaped;
71
+ chunkStart = this.pos;
72
+ } else {
73
+ if (isNewLine(ch)) return null;
74
+ ++this.pos;
75
+ }
76
+ }
77
+ out += this.input.slice(chunkStart, this.pos++);
78
+ return out;
79
+ }
80
+ readEscapedChar() {
81
+ const ch = this.input.charCodeAt(++this.pos);
82
+ let code;
83
+ ++this.pos;
84
+ switch(ch){
85
+ case 110:
86
+ return '\n';
87
+ case 114:
88
+ return '\r';
89
+ case 120:
90
+ code = this.readHexChar(2);
91
+ if (code === null) return null;
92
+ return String.fromCharCode(code);
93
+ case 117:
94
+ code = this.readCodePoint();
95
+ if (code === null) return null;
96
+ return codePointToString(code);
97
+ case 116:
98
+ return '\t';
99
+ case 98:
100
+ return '\b';
101
+ case 118:
102
+ return '\u000b';
103
+ case 102:
104
+ return '\f';
105
+ //@ts-ignore
106
+ case 13:
107
+ if (this.input.charCodeAt(this.pos) === 10) {
108
+ ++this.pos;
109
+ }
110
+ // fall through
111
+ case 10:
112
+ return '';
113
+ case 56:
114
+ case 57:
115
+ return null;
116
+ default:
117
+ if (ch >= 48 && ch <= 55) {
118
+ const match = this.input.slice(this.pos - 1, this.pos + 2).match(/^[0-7]+/);
119
+ if (match === null) return null;
120
+ let octalStr = match[0];
121
+ let octal = parseInt(octalStr, 8);
122
+ if (octal > 255) {
123
+ octalStr = octalStr.slice(0, -1);
124
+ octal = parseInt(octalStr, 8);
125
+ }
126
+ this.pos += octalStr.length - 1;
127
+ const nextCh = this.input.charCodeAt(this.pos);
128
+ if (octalStr !== '0' || nextCh === 56 || nextCh === 57) return null;
129
+ return String.fromCharCode(octal);
130
+ }
131
+ if (isNewLine(ch)) return '';
132
+ return String.fromCharCode(ch);
133
+ }
134
+ }
135
+ readInt(radix, len) {
136
+ const start = this.pos;
137
+ let total = 0;
138
+ for(let i = 0; i < len; ++i, ++this.pos){
139
+ const code = this.input.charCodeAt(this.pos);
140
+ let val;
141
+ if (code >= 97) {
142
+ val = code - 97 + 10;
143
+ } else if (code >= 65) {
144
+ val = code - 65 + 10;
145
+ } else if (code >= 48 && code <= 57) {
146
+ val = code - 48;
147
+ } else {
148
+ val = Infinity;
149
+ }
150
+ if (val >= radix) break;
151
+ total = total * radix + val;
152
+ }
153
+ if (this.pos === start || len != null && this.pos - start !== len) return null;
154
+ return total;
155
+ }
156
+ readHexChar(len) {
157
+ return this.readInt(16, len);
158
+ }
159
+ readCodePoint() {
160
+ const ch = this.input.charCodeAt(this.pos);
161
+ let code;
162
+ if (ch === 123) {
163
+ ++this.pos;
164
+ code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
165
+ ++this.pos;
166
+ if (code && code > 0x10ffff) return null;
167
+ } else {
168
+ code = this.readHexChar(4);
169
+ }
170
+ return code;
171
+ }
172
+ constructor(){
173
+ this.input = '';
174
+ this.pos = 0;
175
+ }
176
+ }
177
+
178
+ exports.Lexer = __webpack_exports__.Lexer;
179
+ for(var __webpack_i__ in __webpack_exports__) {
180
+ if(["Lexer"].indexOf(__webpack_i__) === -1) {
181
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
182
+ }
183
+ }
184
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,138 @@
1
+
2
+ ;// CONCATENATED MODULE: ./src/adapters/lib/lexer.ts
3
+ // simplified from acorn (MIT license)
4
+ function isNewLine(code) {
5
+ return code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
6
+ }
7
+ function codePointToString(ch) {
8
+ if (ch <= 0xffff) return String.fromCharCode(ch);
9
+ ch -= 0x10000;
10
+ return String.fromCharCode((ch >> 10) + 0xd800, (ch & 0x03ff) + 0xdc00);
11
+ }
12
+ class Lexer {
13
+ readString(input, pos) {
14
+ if (pos >= input.length) return null;
15
+ this.input = input;
16
+ this.pos = pos;
17
+ const quote = this.input.charCodeAt(pos);
18
+ if (!(quote === 34 || quote === 39)) return null;
19
+ let out = '';
20
+ let chunkStart = ++this.pos;
21
+ //eslint-disable-next-line no-constant-condition
22
+ while(true){
23
+ if (this.pos >= this.input.length) return null;
24
+ const ch = this.input.charCodeAt(this.pos);
25
+ if (ch === quote) break;
26
+ if (ch === 92) {
27
+ out += this.input.slice(chunkStart, this.pos);
28
+ const escaped = this.readEscapedChar();
29
+ if (escaped === null) return null;
30
+ out += escaped;
31
+ chunkStart = this.pos;
32
+ } else {
33
+ if (isNewLine(ch)) return null;
34
+ ++this.pos;
35
+ }
36
+ }
37
+ out += this.input.slice(chunkStart, this.pos++);
38
+ return out;
39
+ }
40
+ readEscapedChar() {
41
+ const ch = this.input.charCodeAt(++this.pos);
42
+ let code;
43
+ ++this.pos;
44
+ switch(ch){
45
+ case 110:
46
+ return '\n';
47
+ case 114:
48
+ return '\r';
49
+ case 120:
50
+ code = this.readHexChar(2);
51
+ if (code === null) return null;
52
+ return String.fromCharCode(code);
53
+ case 117:
54
+ code = this.readCodePoint();
55
+ if (code === null) return null;
56
+ return codePointToString(code);
57
+ case 116:
58
+ return '\t';
59
+ case 98:
60
+ return '\b';
61
+ case 118:
62
+ return '\u000b';
63
+ case 102:
64
+ return '\f';
65
+ //@ts-ignore
66
+ case 13:
67
+ if (this.input.charCodeAt(this.pos) === 10) {
68
+ ++this.pos;
69
+ }
70
+ // fall through
71
+ case 10:
72
+ return '';
73
+ case 56:
74
+ case 57:
75
+ return null;
76
+ default:
77
+ if (ch >= 48 && ch <= 55) {
78
+ const match = this.input.slice(this.pos - 1, this.pos + 2).match(/^[0-7]+/);
79
+ if (match === null) return null;
80
+ let octalStr = match[0];
81
+ let octal = parseInt(octalStr, 8);
82
+ if (octal > 255) {
83
+ octalStr = octalStr.slice(0, -1);
84
+ octal = parseInt(octalStr, 8);
85
+ }
86
+ this.pos += octalStr.length - 1;
87
+ const nextCh = this.input.charCodeAt(this.pos);
88
+ if (octalStr !== '0' || nextCh === 56 || nextCh === 57) return null;
89
+ return String.fromCharCode(octal);
90
+ }
91
+ if (isNewLine(ch)) return '';
92
+ return String.fromCharCode(ch);
93
+ }
94
+ }
95
+ readInt(radix, len) {
96
+ const start = this.pos;
97
+ let total = 0;
98
+ for(let i = 0; i < len; ++i, ++this.pos){
99
+ const code = this.input.charCodeAt(this.pos);
100
+ let val;
101
+ if (code >= 97) {
102
+ val = code - 97 + 10;
103
+ } else if (code >= 65) {
104
+ val = code - 65 + 10;
105
+ } else if (code >= 48 && code <= 57) {
106
+ val = code - 48;
107
+ } else {
108
+ val = Infinity;
109
+ }
110
+ if (val >= radix) break;
111
+ total = total * radix + val;
112
+ }
113
+ if (this.pos === start || len != null && this.pos - start !== len) return null;
114
+ return total;
115
+ }
116
+ readHexChar(len) {
117
+ return this.readInt(16, len);
118
+ }
119
+ readCodePoint() {
120
+ const ch = this.input.charCodeAt(this.pos);
121
+ let code;
122
+ if (ch === 123) {
123
+ ++this.pos;
124
+ code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
125
+ ++this.pos;
126
+ if (code && code > 0x10ffff) return null;
127
+ } else {
128
+ code = this.readHexChar(4);
129
+ }
130
+ return code;
131
+ }
132
+ constructor(){
133
+ this.input = '';
134
+ this.pos = 0;
135
+ }
136
+ }
137
+
138
+ export { Lexer };