app-bundler 0.2.7 → 0.2.9

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 (3) hide show
  1. package/lib/bundler.js +1421 -1408
  2. package/lib/cli.js +1421 -1408
  3. package/package.json +1 -1
package/lib/bundler.js CHANGED
@@ -2375,7 +2375,10 @@ exports.FileActions = {
2375
2375
  if (/^https?:/.test(path)) {
2376
2376
  return HttpLoader.load(path, opts);
2377
2377
  }
2378
- return global_1.io.File.readAsync(path, opts);
2378
+ return global_1.io.File.readAsync(path, {
2379
+ ...(opts !== null && opts !== void 0 ? opts : {}),
2380
+ cached: false
2381
+ });
2379
2382
  },
2380
2383
  async readDirectory(path, opts) {
2381
2384
  let i = path.indexOf('*');
@@ -4987,8 +4990,9 @@ var __register, __require, require;
4987
4990
  // source ./ESM.js
4988
4991
  $CUSTOM_IMPORTS_CODE$
4989
4992
 
4993
+ var exports = {};
4990
4994
  var module = {
4991
- exports: {}
4995
+ exports: exports
4992
4996
  };
4993
4997
 
4994
4998
  $MODULE$
@@ -5237,115 +5241,89 @@ exports.template_stringifyContent = template_stringifyContent;
5237
5241
 
5238
5242
 
5239
5243
  // source ./ModuleSimplified.js
5240
- var _src_handlers_script_common_js_ModuleWrapper;
5244
+ var _src_handlers_script_import_js_utils;
5241
5245
  (function () {
5242
5246
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5243
5247
  var define = null;
5244
- var exports = _src_handlers_script_common_js_ModuleWrapper != null ? _src_handlers_script_common_js_ModuleWrapper : {};
5248
+ var exports = _src_handlers_script_import_js_utils != null ? _src_handlers_script_import_js_utils : {};
5245
5249
  var module = { exports: exports };
5246
5250
 
5247
5251
  "use strict";
5248
5252
  Object.defineProperty(exports, "__esModule", { value: true });
5249
- exports.ModuleWrapper = void 0;
5250
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5251
- class ModuleWrapper {
5252
- constructor(solution) {
5253
- this.solution = solution;
5254
- }
5255
- wrap(body) {
5256
- let wrapper = this.solution.opts.package.moduleWrapper;
5257
- switch (wrapper) {
5258
- case 'script':
5259
- body = this.wrapSimple(body);
5260
- break;
5261
- case 'iif':
5262
- body = this.wrapWithIIF(body);
5263
- break;
5264
- case 'umd':
5265
- body = this.wrapWithUMD(body);
5266
- break;
5267
- case 'esm':
5268
- body = this.wrapWithESM(body);
5269
- break;
5270
- case 'custom':
5271
- body = this.wrapWithCustom(body);
5272
- break;
5273
- default:
5274
- throw new Error('Uknown module wrapper: ' + wrapper);
5275
- }
5276
- return body;
5277
- }
5278
- wrapSimple(body) {
5279
- return Templates_1.Templates
5280
- .RootModule
5281
- .replace('%BUNDLE%', () => body);
5282
- }
5283
- wrapWithIIF(body) {
5284
- return Templates_1.Templates
5285
- .RootModuleWrapped
5286
- .replace('%BUNDLE%', () => body);
5287
- }
5288
- wrapWithUMD(body) {
5289
- let opts = this.solution.opts.package;
5290
- let name = opts.moduleName || '';
5291
- return Templates_1.Templates
5292
- .UMD
5293
- .replace('%MODULE%', () => body)
5294
- .replace('%NAME%', () => name);
5253
+ exports.u_asString = exports.u_readFile = exports.u_getFilesFromPath = exports.u_makeIndent = exports.u_getIndent = exports.u_getNewLine = void 0;
5254
+ function u_getNewLine(str, io) {
5255
+ var match = /(\r\n)|(\r)|(\n)/.exec(str);
5256
+ return (match && match[0]) || io.env.newLine;
5257
+ }
5258
+ exports.u_getNewLine = u_getNewLine;
5259
+ ;
5260
+ function u_getIndent(str) {
5261
+ var match = /^[ \t]+/.exec(str);
5262
+ return match && match[0] || '';
5263
+ }
5264
+ exports.u_getIndent = u_getIndent;
5265
+ ;
5266
+ function u_makeIndent(str, indent, io) {
5267
+ if (!indent || !str)
5268
+ return str;
5269
+ let newline = u_getNewLine(str, io);
5270
+ return str
5271
+ .split(newline)
5272
+ .map(line => indent + line)
5273
+ .join(newline);
5274
+ }
5275
+ exports.u_makeIndent = u_makeIndent;
5276
+ ;
5277
+ function u_getFilesFromPath(path, io) {
5278
+ var file = new io.File(path);
5279
+ if (file.exists() === false) {
5280
+ console.error('File not found', file.uri.toLocalFile());
5281
+ return [];
5295
5282
  }
5296
- wrapWithESM(body) {
5297
- let opts = this.solution.opts.package;
5298
- let exportsCode = opts.moduleExportsCode || '';
5299
- let importsCode = opts.moduleImportsCode || '';
5300
- let deps = this.solution.outputResources.dynamicDependencies;
5301
- if (deps.length > 0) {
5302
- let arr = deps.map(dep => {
5303
- let key = `bundlerDynamic_${dep.url.replace(/[^\w]/g, '_')}`;
5304
- return {
5305
- url: dep.url,
5306
- key
5307
- };
5308
- });
5309
- let strImports = arr.map(item => `import ${item.key} from '${item.url}';`).join('\n');
5310
- let strCollection = `const bundlerDynamicRepository = {};\n`
5311
- + arr.map(item => `bundlerDynamicRepository['${item.url}'] = ${item.key};`)
5312
- .join('\n');
5313
- let strRequire = [
5314
- `var bundlerOriginalRequire = require || function (url) { throw new Error('Not found: ' + url); };`,
5315
- `var require = function (url) { return bundlerDynamicRepository[url] || bundlerOriginalRequire(url); };`
5316
- ].join('\n');
5317
- importsCode = [
5318
- strImports,
5319
- strCollection,
5320
- strRequire
5321
- ].join('\n');
5322
- }
5323
- return Templates_1.Templates
5324
- .ESM
5325
- .replace('$CUSTOM_IMPORTS_CODE$', () => importsCode)
5326
- .replace('$CUSTOM_EXPORTS_CODE$', () => exportsCode)
5327
- .replace('$MODULE$', () => body);
5283
+ return [file];
5284
+ }
5285
+ exports.u_getFilesFromPath = u_getFilesFromPath;
5286
+ ;
5287
+ function u_readFile(io, file, indent, insertFileName) {
5288
+ var content = file.read().toString();
5289
+ var newline = u_getNewLine(content, io);
5290
+ if (indent) {
5291
+ content = content
5292
+ .split(newline)
5293
+ .map(line => indent + line)
5294
+ .join(newline);
5328
5295
  }
5329
- wrapWithCustom(body) {
5330
- let opts = this.solution.opts.package;
5331
- let template = Templates_1.Templates.load(opts.moduleWrapperCustomPath);
5332
- return template
5333
- .replace('/**MODULE**/', () => body);
5296
+ if (insertFileName) {
5297
+ content = indent
5298
+ + '// source '
5299
+ + file.uri.file
5300
+ + newline
5301
+ + content;
5334
5302
  }
5303
+ return content;
5335
5304
  }
5336
- exports.ModuleWrapper = ModuleWrapper;
5337
- //# sourceMappingURL=ModuleWrapper.js.map
5338
- //# sourceMappingURL=ModuleWrapper.ts.map;
5305
+ exports.u_readFile = u_readFile;
5306
+ ;
5307
+ function u_asString(str) {
5308
+ str = str
5309
+ .replace(/[\n\r]/g, '\\n')
5310
+ .replace(/"/g, '\\"');
5311
+ return `"${str}"`;
5312
+ }
5313
+ exports.u_asString = u_asString;
5314
+ ;
5315
+ //# sourceMappingURL=utils.js.map
5316
+ //# sourceMappingURL=utils.ts.map;
5339
5317
 
5340
5318
  function __isObj(x) {
5341
5319
  return x != null && typeof x === 'object' && x.constructor === Object;
5342
5320
  }
5343
- if (_src_handlers_script_common_js_ModuleWrapper === module.exports) {
5321
+ if (_src_handlers_script_import_js_utils === module.exports) {
5344
5322
  // do nothing if
5345
- } else if (__isObj(_src_handlers_script_common_js_ModuleWrapper) && __isObj(module.exports)) {
5346
- Object.assign(_src_handlers_script_common_js_ModuleWrapper, module.exports);
5323
+ } else if (__isObj(_src_handlers_script_import_js_utils) && __isObj(module.exports)) {
5324
+ Object.assign(_src_handlers_script_import_js_utils, module.exports);
5347
5325
  } else {
5348
- _src_handlers_script_common_js_ModuleWrapper = module.exports;
5326
+ _src_handlers_script_import_js_utils = module.exports;
5349
5327
  }
5350
5328
 
5351
5329
  ;
@@ -5355,215 +5333,107 @@ exports.ModuleWrapper = ModuleWrapper;
5355
5333
 
5356
5334
 
5357
5335
  // source ./ModuleSimplified.js
5358
- var _src_handlers_script_common_js_CommonJsBuilder;
5336
+ var _src_handlers_script_import_js_Dictionary;
5359
5337
  (function () {
5360
5338
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5361
5339
  var define = null;
5362
- var exports = _src_handlers_script_common_js_CommonJsBuilder != null ? _src_handlers_script_common_js_CommonJsBuilder : {};
5340
+ var exports = _src_handlers_script_import_js_Dictionary != null ? _src_handlers_script_import_js_Dictionary : {};
5363
5341
  var module = { exports: exports };
5364
5342
 
5365
5343
  "use strict";
5366
5344
  Object.defineProperty(exports, "__esModule", { value: true });
5367
- exports.CommonJsBuilder = void 0;
5368
- const CommonJsBuilderSimplified_1 = _src_handlers_script_common_js_CommonJsBuilderSimplified;
5369
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5370
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5371
- const template_1 = _src_utils_template;
5372
- const ModuleWrapper_1 = _src_handlers_script_common_js_ModuleWrapper;
5373
- class CommonJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5374
- constructor(solution, handler) {
5375
- super(solution, handler);
5376
- this.solution = solution;
5377
- this.handler = handler;
5378
- var opts = this.solution.opts.package.commonjs;
5379
- if (opts && opts.output === 'simplified') {
5380
- this.wrapModule = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.wrapModule;
5381
- this.getRootContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getRootContent;
5382
- this.getHeaderContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getHeaderContent;
5383
- }
5345
+ exports.Dictionary = void 0;
5346
+ class Dictionary {
5347
+ constructor() {
5348
+ this.hash = {};
5349
+ this.arr = [];
5384
5350
  }
5385
- accepts(resource) {
5386
- if (resource.type !== 'js') {
5387
- return false;
5388
- }
5389
- let module = resource.getModule();
5390
- if (module == null || module === 'root') {
5391
- module = this.solution.opts.package.module;
5351
+ add(...arr) {
5352
+ for (let i = 0; i < arr.length; i++) {
5353
+ let x = arr[i];
5354
+ if (this.hash[x.id] != null) {
5355
+ continue;
5356
+ }
5357
+ this.hash[x.id] = x;
5358
+ this.arr.push(x);
5392
5359
  }
5393
- return module === 'commonjs';
5394
5360
  }
5395
- wrapModule(resource, outputItem, outputItems, setts) {
5396
- var opts = this.solution.iteration;
5397
- if (opts.commonjs == null) {
5398
- opts.commonjs = {
5399
- addHeading: true,
5400
- hasHeading: false
5401
- };
5402
- }
5403
- ;
5404
- var body = '';
5405
- if (opts.commonjs.hasHeading === false && opts.commonjs.addHeading === true) {
5406
- opts.commonjs.hasHeading = true;
5407
- body = this.getHeaderContent();
5361
+ insert(x, i) {
5362
+ if (this.hash[x.id] != null) {
5363
+ this.remove(x);
5408
5364
  }
5409
- var { url, content } = resource;
5410
- var module = Templates_1.Templates
5411
- .Module
5412
- .replace('%MODULE_PATH%', () => url)
5413
- .replace('%MODULE%', () => content)
5414
- .replace('%FOOTER%', () => { var _a, _b; return ((_b = (_a = setts === null || setts === void 0 ? void 0 : setts.partials) === null || _a === void 0 ? void 0 : _a.footer) !== null && _b !== void 0 ? _b : ''); });
5415
- return body + module;
5365
+ this.hash[x.id] = x;
5366
+ this.arr.splice(i, 0, x);
5416
5367
  }
5417
- getHeaderContent() {
5418
- var mainUrl = this.solution.outputResources.rootInput.url;
5419
- return Templates_1.Templates
5420
- .Header
5421
- .replace('%ROOT_DIR%', () => mainUrl);
5368
+ has(x) {
5369
+ return this.hash[x.id] != null;
5422
5370
  }
5423
- buildRoot(root, outputDependencies) {
5424
- outputDependencies.forEach(x => x.embed = true);
5425
- let content = this.getRootContent(root, outputDependencies);
5426
- let body = outputDependencies
5427
- .map(x => {
5428
- let content = x.content;
5429
- if (x.type === 'css') {
5430
- content = (0, template_1.template_interpolate)(Templates_1.Templates.Style, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
5431
- }
5432
- if (x.type === 'mask') {
5433
- content = (0, template_1.template_interpolate)(Templates_1.Templates.Mask, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
5371
+ indexOf(x) {
5372
+ for (let i = 0; i < this.arr.length; i++) {
5373
+ if (this.arr[i].id === x.id) {
5374
+ return i;
5434
5375
  }
5435
- return content;
5436
- })
5437
- .concat([content])
5438
- .join('\n');
5439
- var wrapper = new ModuleWrapper_1.ModuleWrapper(this.solution);
5440
- root.content = wrapper.wrap(body);
5376
+ }
5377
+ return -1;
5441
5378
  }
5442
- getRootContent(root, outputDependencies) {
5443
- return root.content;
5444
- }
5445
- }
5446
- exports.CommonJsBuilder = CommonJsBuilder;
5447
- ;
5448
- //# sourceMappingURL=CommonJsBuilder.js.map
5449
- //# sourceMappingURL=CommonJsBuilder.ts.map;
5450
-
5451
- function __isObj(x) {
5452
- return x != null && typeof x === 'object' && x.constructor === Object;
5453
- }
5454
- if (_src_handlers_script_common_js_CommonJsBuilder === module.exports) {
5455
- // do nothing if
5456
- } else if (__isObj(_src_handlers_script_common_js_CommonJsBuilder) && __isObj(module.exports)) {
5457
- Object.assign(_src_handlers_script_common_js_CommonJsBuilder, module.exports);
5458
- } else {
5459
- _src_handlers_script_common_js_CommonJsBuilder = module.exports;
5460
- }
5461
-
5462
- ;
5463
- }());
5464
-
5465
- // end:source ./ModuleSimplified.js
5466
-
5467
-
5468
- // source ./ModuleSimplified.js
5469
- var _src_handlers_script_common_js_CommonJsPathResolver;
5470
- (function () {
5471
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5472
- var define = null;
5473
- var exports = _src_handlers_script_common_js_CommonJsPathResolver != null ? _src_handlers_script_common_js_CommonJsPathResolver : {};
5474
- var module = { exports: exports };
5475
-
5476
- "use strict";
5477
- Object.defineProperty(exports, "__esModule", { value: true });
5478
- exports.CommonJsPathResolver = void 0;
5479
- const BasePathResolver_1 = _src_handlers_base_BasePathResolver;
5480
- const path_1 = _src_utils_path;
5481
- const global_1 = _src_global;
5482
- class CommonJsPathResolver extends BasePathResolver_1.BasePathResolver {
5483
- accepts(includeData) {
5484
- if (includeData.type !== 'js' || includeData.module !== 'commonjs') {
5485
- return false;
5486
- }
5487
- if (!/^[\w\-/]+$/.test(includeData.url)) {
5488
- return false;
5489
- }
5490
- if (nodeCoreModules.indexOf(includeData.url) !== -1) {
5491
- return false;
5492
- }
5493
- return true;
5494
- }
5495
- resolve(includeData, parentResource) {
5496
- let filename = nodeModuleResolve(includeData.url, parentResource.directory);
5497
- if (filename) {
5498
- let url = this.solution.opts.toAppUrl(filename);
5499
- this.solution.opts.mappings[includeData.url] = url;
5500
- }
5501
- return filename;
5379
+ remove(x) {
5380
+ delete this.hash[x.id];
5381
+ let i = this.arr.findIndex(module => module.id === x.id);
5382
+ this.arr.splice(i, 1);
5502
5383
  }
5503
- }
5504
- exports.CommonJsPathResolver = CommonJsPathResolver;
5505
- ;
5506
- const nodeCoreModules = [
5507
- 'assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
5508
- 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
5509
- 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
5510
- 'tls', 'tty', 'url', 'util', 'vm', 'zlib'
5511
- ];
5512
- function nodeModuleResolve(path, location_) {
5513
- let location = location_.replace(/[\\\/]+$/, '');
5514
- let name = /^([\w\-]+)/.exec(path)[0];
5515
- let resource = path.substring(name.length + 1);
5516
- let current = location;
5517
- let root_ = current + '/node_modules/' + name + '/';
5518
- while (true) {
5519
- let nodeModules = (0, path_1.path_combine)(current, '/node_modules/' + name + '/');
5520
- let pckg = nodeModules + 'package.json';
5521
- if (global_1.io.File.exists(pckg) === false) {
5522
- let next = current.replace(/[^\/\\]+[\/\\]?$/, '');
5523
- if (next === current) {
5524
- return root_ + 'package.json';
5384
+ removeByFn(fn) {
5385
+ let handled = new Dictionary();
5386
+ while (true) {
5387
+ let i = -1, length = this.arr.length;
5388
+ while (++i < length) {
5389
+ let x = this.arr[i];
5390
+ if (handled.has(x)) {
5391
+ continue;
5392
+ }
5393
+ handled.add(x);
5394
+ if (fn(x)) {
5395
+ this.arr.splice(i, 1);
5396
+ delete this.hash[x.id];
5397
+ }
5398
+ break;
5399
+ }
5400
+ if (i === length) {
5401
+ break;
5525
5402
  }
5526
- current = next;
5527
- continue;
5528
5403
  }
5529
- if (resource) {
5530
- let path = nodeModules + resource;
5531
- if (hasExt(path) === false) {
5532
- let likelyTs = path.includes('/src/');
5533
- if (likelyTs) {
5534
- if (global_1.io.File.exists(path + '.ts')) {
5535
- return path + '.ts';
5536
- }
5404
+ }
5405
+ forEach(fn) {
5406
+ let handled = new Dictionary();
5407
+ while (true) {
5408
+ let i = -1, length = this.arr.length;
5409
+ while (++i < length) {
5410
+ let x = this.arr[i];
5411
+ if (handled.has(x)) {
5412
+ continue;
5537
5413
  }
5538
- return path + '.js';
5414
+ handled.add(x);
5415
+ fn(x, i);
5416
+ break;
5417
+ }
5418
+ if (i === length) {
5419
+ break;
5539
5420
  }
5540
- return path;
5541
- }
5542
- let json = global_1.io.File.read(pckg);
5543
- if (typeof json === 'string') {
5544
- json = JSON.parse(json);
5545
- }
5546
- if (json.main) {
5547
- return (0, path_1.path_combine)(nodeModules, json.main);
5548
5421
  }
5549
- return nodeModules + 'index.js';
5550
5422
  }
5551
5423
  }
5552
- function hasExt(path) {
5553
- return /\.[\w]{1,8}($|\?)/.test(path);
5554
- }
5555
- //# sourceMappingURL=CommonJsPathResolver.js.map
5556
- //# sourceMappingURL=CommonJsPathResolver.ts.map;
5424
+ exports.Dictionary = Dictionary;
5425
+ //# sourceMappingURL=Dictionary.js.map
5426
+ //# sourceMappingURL=Dictionary.ts.map;
5557
5427
 
5558
5428
  function __isObj(x) {
5559
5429
  return x != null && typeof x === 'object' && x.constructor === Object;
5560
5430
  }
5561
- if (_src_handlers_script_common_js_CommonJsPathResolver === module.exports) {
5431
+ if (_src_handlers_script_import_js_Dictionary === module.exports) {
5562
5432
  // do nothing if
5563
- } else if (__isObj(_src_handlers_script_common_js_CommonJsPathResolver) && __isObj(module.exports)) {
5564
- Object.assign(_src_handlers_script_common_js_CommonJsPathResolver, module.exports);
5433
+ } else if (__isObj(_src_handlers_script_import_js_Dictionary) && __isObj(module.exports)) {
5434
+ Object.assign(_src_handlers_script_import_js_Dictionary, module.exports);
5565
5435
  } else {
5566
- _src_handlers_script_common_js_CommonJsPathResolver = module.exports;
5436
+ _src_handlers_script_import_js_Dictionary = module.exports;
5567
5437
  }
5568
5438
 
5569
5439
  ;
@@ -5573,41 +5443,35 @@ function hasExt(path) {
5573
5443
 
5574
5444
 
5575
5445
  // source ./ModuleSimplified.js
5576
- var _src_handlers_script_common_js_CommonJsHandler;
5446
+ var _src_handlers_script_import_js_String;
5577
5447
  (function () {
5578
5448
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5579
5449
  var define = null;
5580
- var exports = _src_handlers_script_common_js_CommonJsHandler != null ? _src_handlers_script_common_js_CommonJsHandler : {};
5450
+ var exports = _src_handlers_script_import_js_String != null ? _src_handlers_script_import_js_String : {};
5581
5451
  var module = { exports: exports };
5582
5452
 
5583
5453
  "use strict";
5584
5454
  Object.defineProperty(exports, "__esModule", { value: true });
5585
- exports.CommonJsHandler = void 0;
5586
- const CommonJsParser_1 = _src_handlers_script_common_js_CommonJsParser;
5587
- const CommonJsRewriter_1 = _src_handlers_script_common_js_CommonJsRewriter;
5588
- const CommonJsBuilder_1 = _src_handlers_script_common_js_CommonJsBuilder;
5589
- const CommonJsPathResolver_1 = _src_handlers_script_common_js_CommonJsPathResolver;
5590
- const BaseHandler_1 = _src_handlers_base_BaseHandler;
5591
- class CommonJsHandler extends BaseHandler_1.BaseHandler {
5592
- }
5593
- exports.CommonJsHandler = CommonJsHandler;
5594
- CommonJsHandler.Parser = CommonJsParser_1.CommonJsParser;
5595
- CommonJsHandler.Rewriter = CommonJsRewriter_1.CommonJsRewriter;
5596
- CommonJsHandler.Builder = CommonJsBuilder_1.CommonJsBuilder;
5597
- CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
5598
- ;
5599
- //# sourceMappingURL=CommonJsHandler.js.map
5600
- //# sourceMappingURL=CommonJsHandler.ts.map;
5455
+ exports.String = void 0;
5456
+ var String;
5457
+ (function (String) {
5458
+ function replace(str, i, length, ins = '') {
5459
+ return str.substring(0, i) + ins + str.substring(i + length);
5460
+ }
5461
+ String.replace = replace;
5462
+ })(String = exports.String || (exports.String = {}));
5463
+ //# sourceMappingURL=String.js.map
5464
+ //# sourceMappingURL=String.ts.map;
5601
5465
 
5602
5466
  function __isObj(x) {
5603
5467
  return x != null && typeof x === 'object' && x.constructor === Object;
5604
5468
  }
5605
- if (_src_handlers_script_common_js_CommonJsHandler === module.exports) {
5469
+ if (_src_handlers_script_import_js_String === module.exports) {
5606
5470
  // do nothing if
5607
- } else if (__isObj(_src_handlers_script_common_js_CommonJsHandler) && __isObj(module.exports)) {
5608
- Object.assign(_src_handlers_script_common_js_CommonJsHandler, module.exports);
5471
+ } else if (__isObj(_src_handlers_script_import_js_String) && __isObj(module.exports)) {
5472
+ Object.assign(_src_handlers_script_import_js_String, module.exports);
5609
5473
  } else {
5610
- _src_handlers_script_common_js_CommonJsHandler = module.exports;
5474
+ _src_handlers_script_import_js_String = module.exports;
5611
5475
  }
5612
5476
 
5613
5477
  ;
@@ -5617,112 +5481,255 @@ CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
5617
5481
 
5618
5482
 
5619
5483
  // source ./ModuleSimplified.js
5620
- var _src_handlers_script_amd_js_AmdJsParser;
5484
+ var _src_handlers_script_import_js_ModuleFile;
5621
5485
  (function () {
5622
5486
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5623
5487
  var define = null;
5624
- var exports = _src_handlers_script_amd_js_AmdJsParser != null ? _src_handlers_script_amd_js_AmdJsParser : {};
5488
+ var exports = _src_handlers_script_import_js_ModuleFile != null ? _src_handlers_script_import_js_ModuleFile : {};
5625
5489
  var module = { exports: exports };
5626
5490
 
5627
5491
  "use strict";
5628
5492
  Object.defineProperty(exports, "__esModule", { value: true });
5629
- exports.AmdJsParser = void 0;
5630
- const BaseParser_1 = _src_handlers_base_BaseParser;
5631
- const AstUtil_1 = _src_handlers_script_utils_AstUtil;
5632
- const atma_utils_1 = require("atma-utils");
5633
- const Include_1 = _src_class_Include;
5634
- class AmdJsParser extends BaseParser_1.BaseParser {
5635
- getDependencies(ast, ownerResource) {
5636
- let info = {
5637
- dependencies: []
5638
- };
5639
- AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.amdFunction, (node, descend) => {
5640
- let scope = node.scope || ast;
5641
- let deps = this._process(node, scope);
5642
- if (deps) {
5643
- info.dependencies.push(...deps);
5493
+ exports.ModuleFile = exports.IImporterOptions = void 0;
5494
+ const io = require("atma-io");
5495
+ const utils_1 = _src_handlers_script_import_js_utils;
5496
+ const Dictionary_1 = _src_handlers_script_import_js_Dictionary;
5497
+ const String_1 = _src_handlers_script_import_js_String;
5498
+ class IImporterOptions {
5499
+ constructor() {
5500
+ this.removeUnusedExports = true;
5501
+ this.wrapper = 'iif';
5502
+ this.lazy = null;
5503
+ }
5504
+ }
5505
+ exports.IImporterOptions = IImporterOptions;
5506
+ class ModuleFile {
5507
+ constructor(content, file) {
5508
+ this.content = content;
5509
+ this.file = file;
5510
+ this.outer = new Dictionary_1.Dictionary();
5511
+ this.scoped = new Dictionary_1.Dictionary();
5512
+ this.imports = [];
5513
+ this.exports = [];
5514
+ this.scopedVars = [];
5515
+ this.id = file.uri.toLocalFile();
5516
+ this.path = file.uri.toRelativeString(io.env.currentDir);
5517
+ }
5518
+ hasDeep(x, ignore, hash = new Dictionary_1.Dictionary()) {
5519
+ function check(arr) {
5520
+ for (let i = 0; i < arr.length; i++) {
5521
+ let module = arr[i];
5522
+ if (module == ignore || hash.has(module)) {
5523
+ continue;
5524
+ }
5525
+ hash.add(module);
5526
+ let has = module.hasDeep(x, ignore, hash);
5527
+ if (has) {
5528
+ return true;
5529
+ }
5644
5530
  }
5531
+ return false;
5532
+ }
5533
+ if (this.id === x.id) {
5645
5534
  return true;
5646
- });
5647
- return new atma_utils_1.class_Dfr().resolve(info);
5535
+ }
5536
+ return check(this.outer.arr) || check(this.scoped.arr);
5648
5537
  }
5649
- _process(node, scope) {
5650
- if (node.args.length < 2) {
5651
- return;
5538
+ getAllModules() {
5539
+ let dict = new Dictionary_1.Dictionary();
5540
+ function add(module) {
5541
+ if (dict.has(module)) {
5542
+ return;
5543
+ }
5544
+ dict.add(module);
5545
+ module.outer.forEach(add);
5546
+ module.scoped.forEach(add);
5652
5547
  }
5653
- let args = AstUtil_1.AstUtil.getArguments(node.args, scope);
5654
- let res = new Include_1.Include();
5655
- let dependencies = args.find(x => Array.isArray(x));
5656
- if (dependencies == null) {
5657
- return;
5548
+ add(this);
5549
+ return dict.arr;
5550
+ }
5551
+ static getAllImports(modules) {
5552
+ let arr = [];
5553
+ modules.filter(x => x.imports != null).forEach(x => arr.push(...x.imports));
5554
+ return arr;
5555
+ // function read (module: ModuleFile, stack: ModuleFile[] = []): ImportNode[] {
5556
+ // if (stack.includes(module) || module.imports == null) {
5557
+ // return [];
5558
+ // }
5559
+ // stack.push(module);
5560
+ // let arr = [...module.imports];
5561
+ // module.imports.forEach(x => arr.push(...read(x.module, stack)));
5562
+ // return arr;
5563
+ // }
5564
+ // return read(this);
5565
+ }
5566
+ toScript(parents = [], options, indent = '') {
5567
+ let newLine = (0, utils_1.u_getNewLine)(this.content, io);
5568
+ let outerContent = this
5569
+ .outer
5570
+ .arr
5571
+ .map(x => x.toScript([...parents, this], options))
5572
+ .map(x => x.replace(/[\s]*$/, ''))
5573
+ .join(newLine);
5574
+ let scopedContent = this
5575
+ .scoped
5576
+ .arr
5577
+ .map(x => x.toScript([...parents, this], options))
5578
+ .map(x => x.replace(/[\s]*$/, ''))
5579
+ .join(newLine);
5580
+ let scopedRefs = this
5581
+ .scopedVars
5582
+ .filter(x => !options.removeUnusedExports || x.dependents.length > 0)
5583
+ .map(x => ` ${x.ref}`)
5584
+ .join(`,${newLine}`);
5585
+ if (scopedRefs) {
5586
+ scopedRefs = String_1.String.replace(scopedRefs, 0, 3, 'var');
5587
+ scopedRefs += ';';
5588
+ scopedContent = scopedRefs + newLine + scopedContent;
5658
5589
  }
5659
- let groups = Include_1.Include.groupByType(dependencies, this.solution.opts);
5660
- for (let type in groups) {
5661
- res[type].apply(res, groups[type]);
5590
+ let content = this.content;
5591
+ // normalize exports
5592
+ this.exports.reverse().forEach(x => {
5593
+ if (options.removeUnusedExports && x.dependents.length === 0) {
5594
+ let str = content.substring(x.position, x.position + x.length);
5595
+ str = str.replace(/\s*export\s*/g, '');
5596
+ content = String_1.String.replace(content, x.position, x.length, str);
5597
+ return;
5598
+ }
5599
+ switch (x.type) {
5600
+ case 'ref':
5601
+ content = String_1.String.replace(content, x.position, x.length, x.ref);
5602
+ break;
5603
+ case 'function':
5604
+ content = String_1.String.replace(content, x.position, x.length, `${x.ref} = function `);
5605
+ break;
5606
+ case 'named':
5607
+ content = String_1.String.replace(content, x.position, x.length, '');
5608
+ break;
5609
+ case 'scoped':
5610
+ if (x.length > 0) {
5611
+ content = String_1.String.replace(content, x.position, x.length, '');
5612
+ }
5613
+ break;
5614
+ }
5615
+ });
5616
+ // remove imports
5617
+ this.imports.reverse().forEach(x => {
5618
+ content = String_1.String.replace(content, x.position, x.length, '');
5619
+ });
5620
+ // create var declaration
5621
+ let externalRefs = '';
5622
+ if (this.exports.length > 0) {
5623
+ this
5624
+ .exports
5625
+ .filter(x => {
5626
+ return x.dependents.length > 0 || options.removeUnusedExports === false;
5627
+ })
5628
+ .forEach(x => {
5629
+ /** Remove local scoped var declaration and make it global scoped */
5630
+ if (x.type === 'scoped') {
5631
+ let rgx = new RegExp(`\\b(var|let|const|function)\\s+${x.ref}`);
5632
+ content = content.replace(rgx, x.ref);
5633
+ }
5634
+ return x;
5635
+ });
5636
+ externalRefs = this
5637
+ .exports
5638
+ .reverse()
5639
+ .filter(x => {
5640
+ if (x.builder.movedToOuter) {
5641
+ return false;
5642
+ }
5643
+ if (options.removeUnusedExports === false) {
5644
+ return true;
5645
+ }
5646
+ if (x.dependents.length === 0) {
5647
+ console.warn(`Module ${this.id} has unused export ${x.ref}`);
5648
+ return false;
5649
+ }
5650
+ return true;
5651
+ })
5652
+ .filter(x => {
5653
+ let exportInOuter = parents
5654
+ .some(p => {
5655
+ let parentsExport = p.exports.find(e => e.hasExport(x.ref));
5656
+ if (parentsExport == null) {
5657
+ return false;
5658
+ }
5659
+ if (options.removeUnusedExports && parentsExport.dependents.length === 0) {
5660
+ return false;
5661
+ }
5662
+ return true;
5663
+ });
5664
+ return exportInOuter === false;
5665
+ })
5666
+ .map(x => ` ${x.ref}`)
5667
+ .join(`,${newLine}`);
5668
+ if (externalRefs.length > 0) {
5669
+ externalRefs = String_1.String.replace(externalRefs, 0, 3, 'var');
5670
+ externalRefs += ';';
5671
+ }
5662
5672
  }
5663
- res.includes.forEach(x => x.module = 'amd');
5664
- let ignore = ['exports', 'require'];
5665
- res.includes = res.includes.filter(x => ignore.indexOf(x.url) === -1);
5666
- return res.includes;
5667
- }
5668
- }
5669
- exports.AmdJsParser = AmdJsParser;
5670
- ;
5671
- //# sourceMappingURL=AmdJsParser.js.map
5672
- //# sourceMappingURL=AmdJsParser.ts.map;
5673
-
5674
- function __isObj(x) {
5675
- return x != null && typeof x === 'object' && x.constructor === Object;
5676
- }
5677
- if (_src_handlers_script_amd_js_AmdJsParser === module.exports) {
5678
- // do nothing if
5679
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsParser) && __isObj(module.exports)) {
5680
- Object.assign(_src_handlers_script_amd_js_AmdJsParser, module.exports);
5681
- } else {
5682
- _src_handlers_script_amd_js_AmdJsParser = module.exports;
5683
- }
5684
-
5685
- ;
5686
- }());
5687
-
5688
- // end:source ./ModuleSimplified.js
5689
-
5690
-
5691
- // source ./ModuleSimplified.js
5692
- var _src_handlers_script_amd_js_AmdJsRewriter;
5693
- (function () {
5694
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5695
- var define = null;
5696
- var exports = _src_handlers_script_amd_js_AmdJsRewriter != null ? _src_handlers_script_amd_js_AmdJsRewriter : {};
5697
- var module = { exports: exports };
5698
-
5699
- "use strict";
5700
- Object.defineProperty(exports, "__esModule", { value: true });
5701
- exports.AmdJsRewriter = void 0;
5702
- const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
5703
- class AmdJsRewriter extends BaseRewriter_1.BaseRewriter {
5704
- rewritePartial(content, ownerResource) {
5673
+ const SPACE = '\t';
5674
+ let indentScopedContent = `${(0, utils_1.u_makeIndent)(scopedContent || '', SPACE, io)}`;
5675
+ let indentContent = `${(0, utils_1.u_makeIndent)(content, SPACE, io)}`;
5676
+ let scopeLess = parents.length === 0 && options.wrapper !== 'iif';
5677
+ content = [
5678
+ `${outerContent}` || '',
5679
+ `${externalRefs}` || '',
5680
+ !scopeLess && (indentScopedContent || indentContent) ? `(function(){` : '',
5681
+ indentScopedContent,
5682
+ indentContent,
5683
+ !scopeLess && (indentScopedContent || indentContent) ? `}());` : ''
5684
+ ]
5685
+ .filter(x => !!x)
5686
+ .join(newLine);
5687
+ return (0, utils_1.u_makeIndent)(content, indent, io);
5705
5688
  }
5706
- rewriteResource(resource) {
5689
+ toImportsJson() {
5690
+ function toJSON(module) {
5691
+ var json = {
5692
+ id: module.id,
5693
+ imports: null
5694
+ };
5695
+ if (module.imports) {
5696
+ json.imports = module.imports.map(x => toJSON(x.module));
5697
+ }
5698
+ return json;
5699
+ }
5700
+ return toJSON(this);
5707
5701
  }
5708
- accepts(type) {
5709
- return type === 'mask';
5702
+ toModulesJson() {
5703
+ function toJSON(module) {
5704
+ let json = {
5705
+ id: module.id,
5706
+ outer: module.outer.arr.map(x => toJSON(x)),
5707
+ scoped: module.scoped.arr.map(x => toJSON(x))
5708
+ };
5709
+ if (json.outer.length === 0) {
5710
+ delete json.outer;
5711
+ }
5712
+ if (json.scoped.length === 0) {
5713
+ delete json.scoped;
5714
+ }
5715
+ return json;
5716
+ }
5717
+ return toJSON(this);
5710
5718
  }
5711
5719
  }
5712
- exports.AmdJsRewriter = AmdJsRewriter;
5713
- ;
5714
- //# sourceMappingURL=AmdJsRewriter.js.map
5715
- //# sourceMappingURL=AmdJsRewriter.ts.map;
5720
+ exports.ModuleFile = ModuleFile;
5721
+ //# sourceMappingURL=ModuleFile.js.map
5722
+ //# sourceMappingURL=ModuleFile.ts.map;
5716
5723
 
5717
5724
  function __isObj(x) {
5718
5725
  return x != null && typeof x === 'object' && x.constructor === Object;
5719
5726
  }
5720
- if (_src_handlers_script_amd_js_AmdJsRewriter === module.exports) {
5727
+ if (_src_handlers_script_import_js_ModuleFile === module.exports) {
5721
5728
  // do nothing if
5722
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsRewriter) && __isObj(module.exports)) {
5723
- Object.assign(_src_handlers_script_amd_js_AmdJsRewriter, module.exports);
5729
+ } else if (__isObj(_src_handlers_script_import_js_ModuleFile) && __isObj(module.exports)) {
5730
+ Object.assign(_src_handlers_script_import_js_ModuleFile, module.exports);
5724
5731
  } else {
5725
- _src_handlers_script_amd_js_AmdJsRewriter = module.exports;
5732
+ _src_handlers_script_import_js_ModuleFile = module.exports;
5726
5733
  }
5727
5734
 
5728
5735
  ;
@@ -5732,91 +5739,208 @@ exports.AmdJsRewriter = AmdJsRewriter;
5732
5739
 
5733
5740
 
5734
5741
  // source ./ModuleSimplified.js
5735
- var _src_handlers_script_amd_js_AmdJsBuilder;
5742
+ var _src_handlers_script_import_js_Parser;
5736
5743
  (function () {
5737
5744
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5738
5745
  var define = null;
5739
- var exports = _src_handlers_script_amd_js_AmdJsBuilder != null ? _src_handlers_script_amd_js_AmdJsBuilder : {};
5746
+ var exports = _src_handlers_script_import_js_Parser != null ? _src_handlers_script_import_js_Parser : {};
5740
5747
  var module = { exports: exports };
5741
5748
 
5742
5749
  "use strict";
5743
5750
  Object.defineProperty(exports, "__esModule", { value: true });
5744
- exports.AmdJsBuilder = void 0;
5745
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5746
- class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5747
- buildRoot(resource, dependencies) {
5748
- }
5749
- wrapModule(resource, outputItem) {
5750
- return resource.content;
5751
+ exports.Parser = void 0;
5752
+ const ModuleFile_1 = _src_handlers_script_import_js_ModuleFile;
5753
+ const ResourceInfo_1 = _src_class_ResourceInfo;
5754
+ let Rgx = {
5755
+ Imports: {
5756
+ full: {
5757
+ rgx: /^[ \t]*import\s*(\*\s+as\s+\w+\s+from\s+)?['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5758
+ map(match) {
5759
+ let $import = new ResourceInfo_1.ImportNode();
5760
+ $import.position = match.index;
5761
+ $import.length = match[0].length;
5762
+ $import.type = 'full';
5763
+ $import.path = match.groups.path;
5764
+ return $import;
5765
+ }
5766
+ },
5767
+ refs: {
5768
+ rgx: /^[ \t]*import\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5769
+ map(match) {
5770
+ let $import = new ResourceInfo_1.ImportNode();
5771
+ $import.position = match.index;
5772
+ $import.length = match[0].length;
5773
+ $import.type = 'refs';
5774
+ $import.path = match[2];
5775
+ $import.refs = match[1].split(',').map(x => x.trim());
5776
+ return $import;
5777
+ }
5778
+ },
5779
+ defaults: {
5780
+ rgx: /^[ \t]*import\s+(?<def>\w+)\s+from\s*['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5781
+ map(match) {
5782
+ let $import = new ResourceInfo_1.ImportNode();
5783
+ $import.position = match.index;
5784
+ $import.length = match[0].length;
5785
+ $import.type = 'full';
5786
+ $import.path = match.groups.path;
5787
+ return $import;
5788
+ }
5789
+ },
5790
+ exportAll: {
5791
+ rgx: /^[ \t]*export\s+\*\s+from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5792
+ map(match) {
5793
+ let $import = new ResourceInfo_1.ImportNode();
5794
+ $import.position = match.index;
5795
+ $import.length = match[0].length;
5796
+ $import.type = 'exportAll';
5797
+ $import.path = match[1];
5798
+ $import.exportAll = true;
5799
+ return $import;
5800
+ }
5801
+ },
5802
+ exportRefs: {
5803
+ rgx: /^[ \t]*export\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5804
+ map(match) {
5805
+ let $import = new ResourceInfo_1.ImportNode();
5806
+ $import.position = match.index;
5807
+ $import.length = match[0].length;
5808
+ $import.type = 'exportRefs';
5809
+ $import.path = match[2];
5810
+ $import.refs = match[1].split(',').map(x => x.trim());
5811
+ $import.exportRefs = true;
5812
+ return $import;
5813
+ }
5814
+ }
5815
+ },
5816
+ Exports: {
5817
+ ref: {
5818
+ rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[^\w\d_$;])/gm,
5819
+ map(match) {
5820
+ let $export = new ResourceInfo_1.ExportNode();
5821
+ $export.position = match.index;
5822
+ $export.length = match[0].length;
5823
+ $export.type = 'ref';
5824
+ $export.ref = match[2];
5825
+ return $export;
5826
+ }
5827
+ },
5828
+ named: {
5829
+ rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[;])/gm,
5830
+ map(match) {
5831
+ let $export = new ResourceInfo_1.ExportNode();
5832
+ $export.position = match.index;
5833
+ $export.length = match[0].length;
5834
+ $export.type = 'named';
5835
+ $export.ref = match[2];
5836
+ return $export;
5837
+ }
5838
+ },
5839
+ scoped: {
5840
+ rgx: /^[ \t]*export\s*\{([^}]+)}\s*;?(?!\s*from)/gm,
5841
+ map(match) {
5842
+ let refs = match[1].split(',').map(x => x.trim());
5843
+ let $export = new ResourceInfo_1.ExportNode();
5844
+ $export.position = match.index;
5845
+ $export.length = match[0].length;
5846
+ $export.type = 'scoped';
5847
+ $export.ref = refs[0];
5848
+ let other = refs.slice(1).map(ref => {
5849
+ let $export = new ResourceInfo_1.ExportNode();
5850
+ $export.position = match.index;
5851
+ $export.length = 0;
5852
+ $export.type = 'scoped';
5853
+ $export.ref = ref;
5854
+ return $export;
5855
+ });
5856
+ return [$export, ...other];
5857
+ }
5858
+ },
5859
+ function: {
5860
+ rgx: /^[ \t]*export\s*function\s+([\w\d_$]+)/gm,
5861
+ map(match) {
5862
+ let $export = new ResourceInfo_1.ExportNode();
5863
+ $export.position = match.index;
5864
+ $export.length = match[0].length;
5865
+ $export.type = 'function';
5866
+ $export.ref = match[1];
5867
+ return $export;
5868
+ }
5869
+ }
5751
5870
  }
5752
- accepts(resource) {
5753
- if (resource.type !== 'js') {
5754
- return false;
5871
+ };
5872
+ class Parser {
5873
+ static supports(content) {
5874
+ for (let type in Rgx) {
5875
+ for (let key in Rgx[type]) {
5876
+ let rgx = Rgx[type][key].rgx;
5877
+ rgx.lastIndex = 0;
5878
+ if (rgx.test(content)) {
5879
+ return true;
5880
+ }
5881
+ }
5755
5882
  }
5756
- let module = resource.getModule();
5757
- if (module === 'root' && resource.solution.opts.package.module === 'amd') {
5758
- module = 'amd';
5883
+ return false;
5884
+ }
5885
+ static parse(content, file) {
5886
+ let module = new ModuleFile_1.ModuleFile(content, file);
5887
+ if (Parser.supports(content) === false) {
5888
+ return module;
5759
5889
  }
5760
- return module === 'amd';
5890
+ for (let key in Rgx.Imports) {
5891
+ let x = Rgx.Imports[key];
5892
+ x.rgx.lastIndex = 0;
5893
+ for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
5894
+ let result = x.map(match, content);
5895
+ if (Array.isArray(result)) {
5896
+ module.imports.push(...result);
5897
+ }
5898
+ else {
5899
+ module.imports.push(result);
5900
+ }
5901
+ }
5902
+ }
5903
+ for (let key in Rgx.Exports) {
5904
+ let x = Rgx.Exports[key];
5905
+ x.rgx.lastIndex = 0;
5906
+ for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
5907
+ let result = x.map(match, content);
5908
+ if (Array.isArray(result)) {
5909
+ module.exports.push(...result);
5910
+ }
5911
+ else {
5912
+ module.exports.push(result);
5913
+ }
5914
+ }
5915
+ }
5916
+ module.imports.forEach(m => m.parent = module);
5917
+ module.imports.filter(x => x.type === 'exportRefs').forEach(imp => {
5918
+ imp.refs.forEach(ref => {
5919
+ let exp = new ResourceInfo_1.ExportNode();
5920
+ exp.position = 0;
5921
+ exp.length = 0;
5922
+ exp.ref = ref;
5923
+ module.exports.push(exp);
5924
+ });
5925
+ });
5926
+ module.imports.sort((a, b) => a.position < b.position ? -1 : 1);
5927
+ module.exports.sort((a, b) => a.position < b.position ? -1 : 1);
5928
+ return module;
5761
5929
  }
5762
5930
  }
5763
- exports.AmdJsBuilder = AmdJsBuilder;
5764
- ;
5765
- //# sourceMappingURL=AmdJsBuilder.js.map
5766
- //# sourceMappingURL=AmdJsBuilder.ts.map;
5767
-
5768
- function __isObj(x) {
5769
- return x != null && typeof x === 'object' && x.constructor === Object;
5770
- }
5771
- if (_src_handlers_script_amd_js_AmdJsBuilder === module.exports) {
5772
- // do nothing if
5773
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsBuilder) && __isObj(module.exports)) {
5774
- Object.assign(_src_handlers_script_amd_js_AmdJsBuilder, module.exports);
5775
- } else {
5776
- _src_handlers_script_amd_js_AmdJsBuilder = module.exports;
5777
- }
5778
-
5779
- ;
5780
- }());
5781
-
5782
- // end:source ./ModuleSimplified.js
5783
-
5784
-
5785
- // source ./ModuleSimplified.js
5786
- var _src_handlers_script_amd_js_AmdJsHandler;
5787
- (function () {
5788
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5789
- var define = null;
5790
- var exports = _src_handlers_script_amd_js_AmdJsHandler != null ? _src_handlers_script_amd_js_AmdJsHandler : {};
5791
- var module = { exports: exports };
5792
-
5793
- "use strict";
5794
- Object.defineProperty(exports, "__esModule", { value: true });
5795
- exports.AmdJsHandler = void 0;
5796
- const AmdJsParser_1 = _src_handlers_script_amd_js_AmdJsParser;
5797
- const AmdJsRewriter_1 = _src_handlers_script_amd_js_AmdJsRewriter;
5798
- const AmdJsBuilder_1 = _src_handlers_script_amd_js_AmdJsBuilder;
5799
- const BaseHandler_1 = _src_handlers_base_BaseHandler;
5800
- class AmdJsHandler extends BaseHandler_1.BaseHandler {
5801
- }
5802
- exports.AmdJsHandler = AmdJsHandler;
5803
- AmdJsHandler.Parser = AmdJsParser_1.AmdJsParser;
5804
- AmdJsHandler.Rewriter = AmdJsRewriter_1.AmdJsRewriter;
5805
- AmdJsHandler.Builder = AmdJsBuilder_1.AmdJsBuilder;
5806
- AmdJsHandler.PathResolver = null;
5807
- ;
5808
- //# sourceMappingURL=AmdJsHandler.js.map
5809
- //# sourceMappingURL=AmdJsHandler.ts.map;
5931
+ exports.Parser = Parser;
5932
+ //# sourceMappingURL=Parser.js.map
5933
+ //# sourceMappingURL=Parser.ts.map;
5810
5934
 
5811
5935
  function __isObj(x) {
5812
5936
  return x != null && typeof x === 'object' && x.constructor === Object;
5813
5937
  }
5814
- if (_src_handlers_script_amd_js_AmdJsHandler === module.exports) {
5938
+ if (_src_handlers_script_import_js_Parser === module.exports) {
5815
5939
  // do nothing if
5816
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsHandler) && __isObj(module.exports)) {
5817
- Object.assign(_src_handlers_script_amd_js_AmdJsHandler, module.exports);
5940
+ } else if (__isObj(_src_handlers_script_import_js_Parser) && __isObj(module.exports)) {
5941
+ Object.assign(_src_handlers_script_import_js_Parser, module.exports);
5818
5942
  } else {
5819
- _src_handlers_script_amd_js_AmdJsHandler = module.exports;
5943
+ _src_handlers_script_import_js_Parser = module.exports;
5820
5944
  }
5821
5945
 
5822
5946
  ;
@@ -5826,70 +5950,124 @@ AmdJsHandler.PathResolver = null;
5826
5950
 
5827
5951
 
5828
5952
  // source ./ModuleSimplified.js
5829
- var _src_class_ResourcePropMapping;
5953
+ var _src_handlers_script_common_js_ModuleWrapper;
5830
5954
  (function () {
5831
5955
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5832
5956
  var define = null;
5833
- var exports = _src_class_ResourcePropMapping != null ? _src_class_ResourcePropMapping : {};
5957
+ var exports = _src_handlers_script_common_js_ModuleWrapper != null ? _src_handlers_script_common_js_ModuleWrapper : {};
5834
5958
  var module = { exports: exports };
5835
5959
 
5836
5960
  "use strict";
5837
5961
  Object.defineProperty(exports, "__esModule", { value: true });
5838
- exports.ResourcePropMapping = void 0;
5839
- class ResourcePropMapping {
5840
- constructor(resA, resB) {
5841
- this.resA = resA;
5842
- this.resB = resB;
5843
- }
5844
- map(resource) {
5845
- let match = true;
5846
- for (let key in this.resA) {
5847
- let val = this.resA[key];
5848
- if (val == null)
5849
- continue;
5850
- let currentVal = resource[key];
5851
- if (typeof val === 'function') {
5852
- match = val(currentVal);
5853
- }
5854
- if (val instanceof RegExp) {
5855
- match = val.exec(currentVal) != null;
5856
- }
5857
- if (typeof val === 'string' || typeof val === 'number') {
5858
- match = val === currentVal;
5859
- }
5860
- if (match == false) {
5861
- return resource;
5862
- }
5962
+ exports.ModuleWrapper = void 0;
5963
+ const global_1 = _src_global;
5964
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5965
+ const Parser_1 = _src_handlers_script_import_js_Parser;
5966
+ class ModuleWrapper {
5967
+ constructor(solution) {
5968
+ this.solution = solution;
5969
+ }
5970
+ wrap(body) {
5971
+ let wrapper = this.solution.opts.package.moduleWrapper;
5972
+ switch (wrapper) {
5973
+ case 'script':
5974
+ body = this.wrapSimple(body);
5975
+ break;
5976
+ case 'iif':
5977
+ body = this.wrapWithIIF(body);
5978
+ break;
5979
+ case 'umd':
5980
+ body = this.wrapWithUMD(body);
5981
+ break;
5982
+ case 'esm':
5983
+ body = this.wrapWithESM(body);
5984
+ break;
5985
+ case 'custom':
5986
+ body = this.wrapWithCustom(body);
5987
+ break;
5988
+ default:
5989
+ throw new Error('Uknown module wrapper: ' + wrapper);
5863
5990
  }
5864
- let clone = resource.clone();
5865
- for (let key in this.resB) {
5866
- let val = this.resB[key];
5867
- let currentVal = resource[key];
5868
- if (typeof val === 'function') {
5869
- clone[key] = val(currentVal, resource);
5870
- continue;
5871
- }
5872
- if (typeof val === 'string' || typeof val === 'boolean') {
5873
- clone[key] = val;
5874
- continue;
5875
- }
5991
+ return body;
5992
+ }
5993
+ wrapSimple(body) {
5994
+ return Templates_1.Templates
5995
+ .RootModule
5996
+ .replace('%BUNDLE%', () => body);
5997
+ }
5998
+ wrapWithIIF(body) {
5999
+ return Templates_1.Templates
6000
+ .RootModuleWrapped
6001
+ .replace('%BUNDLE%', () => body);
6002
+ }
6003
+ wrapWithUMD(body) {
6004
+ let opts = this.solution.opts.package;
6005
+ let name = opts.moduleName || '';
6006
+ return Templates_1.Templates
6007
+ .UMD
6008
+ .replace('%MODULE%', () => body)
6009
+ .replace('%NAME%', () => name);
6010
+ }
6011
+ wrapWithESM(body) {
6012
+ let opts = this.solution.opts.package;
6013
+ let exportsCode = opts.moduleExportsCode || '';
6014
+ let importsCode = opts.moduleImportsCode || '';
6015
+ let deps = this.solution.outputResources.dynamicDependencies;
6016
+ if (deps.length > 0) {
6017
+ let arr = deps.map(dep => {
6018
+ let key = `bundlerDynamic_${dep.url.replace(/[^\w]/g, '_')}`;
6019
+ return {
6020
+ url: dep.url,
6021
+ key
6022
+ };
6023
+ });
6024
+ let strImports = arr.map(item => `import ${item.key} from '${item.url}';`).join('\n');
6025
+ let strCollection = `const bundlerDynamicRepository = {};\n`
6026
+ + arr.map(item => `bundlerDynamicRepository['${item.url}'] = ${item.key};`)
6027
+ .join('\n');
6028
+ let strRequire = [
6029
+ `var bundlerOriginalRequire = require || function (url) { throw new Error('Not found: ' + url); };`,
6030
+ `var require = function (url) { return bundlerDynamicRepository[url] || bundlerOriginalRequire(url); };`
6031
+ ].join('\n');
6032
+ importsCode = [
6033
+ strImports,
6034
+ strCollection,
6035
+ strRequire
6036
+ ].join('\n');
5876
6037
  }
5877
- return clone;
6038
+ let rootPath = this.solution.path;
6039
+ let rootContentRaw = global_1.io.File.read(rootPath, { cached: false, skipHooks: true, encoding: 'utf8' });
6040
+ let module = Parser_1.Parser.parse(rootContentRaw, new global_1.io.File(this.solution.path));
6041
+ let exportsBefore = module.exports.map(x => {
6042
+ return `export const ${x.ref} = module.exports.${x.ref};`;
6043
+ }).join('\n');
6044
+ exportsCode = `${exportsBefore}\n${exportsCode}`;
6045
+ return Templates_1.Templates
6046
+ .ESM
6047
+ .replace('$CUSTOM_IMPORTS_CODE$', () => importsCode)
6048
+ .replace('$CUSTOM_EXPORTS_CODE$', () => exportsCode)
6049
+ .replace('$MODULE$', () => body);
6050
+ }
6051
+ wrapWithCustom(body) {
6052
+ let opts = this.solution.opts.package;
6053
+ let template = Templates_1.Templates.load(opts.moduleWrapperCustomPath);
6054
+ return template
6055
+ .replace('/**MODULE**/', () => body);
5878
6056
  }
5879
6057
  }
5880
- exports.ResourcePropMapping = ResourcePropMapping;
5881
- //# sourceMappingURL=ResourcePropMapping.js.map
5882
- //# sourceMappingURL=ResourcePropMapping.ts.map;
6058
+ exports.ModuleWrapper = ModuleWrapper;
6059
+ //# sourceMappingURL=ModuleWrapper.js.map
6060
+ //# sourceMappingURL=ModuleWrapper.ts.map;
5883
6061
 
5884
6062
  function __isObj(x) {
5885
6063
  return x != null && typeof x === 'object' && x.constructor === Object;
5886
6064
  }
5887
- if (_src_class_ResourcePropMapping === module.exports) {
6065
+ if (_src_handlers_script_common_js_ModuleWrapper === module.exports) {
5888
6066
  // do nothing if
5889
- } else if (__isObj(_src_class_ResourcePropMapping) && __isObj(module.exports)) {
5890
- Object.assign(_src_class_ResourcePropMapping, module.exports);
6067
+ } else if (__isObj(_src_handlers_script_common_js_ModuleWrapper) && __isObj(module.exports)) {
6068
+ Object.assign(_src_handlers_script_common_js_ModuleWrapper, module.exports);
5891
6069
  } else {
5892
- _src_class_ResourcePropMapping = module.exports;
6070
+ _src_handlers_script_common_js_ModuleWrapper = module.exports;
5893
6071
  }
5894
6072
 
5895
6073
  ;
@@ -5899,200 +6077,108 @@ exports.ResourcePropMapping = ResourcePropMapping;
5899
6077
 
5900
6078
 
5901
6079
  // source ./ModuleSimplified.js
5902
- var _src_handlers_script_include_js_IncludeJsParser;
6080
+ var _src_handlers_script_common_js_CommonJsBuilder;
5903
6081
  (function () {
5904
6082
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5905
6083
  var define = null;
5906
- var exports = _src_handlers_script_include_js_IncludeJsParser != null ? _src_handlers_script_include_js_IncludeJsParser : {};
6084
+ var exports = _src_handlers_script_common_js_CommonJsBuilder != null ? _src_handlers_script_common_js_CommonJsBuilder : {};
5907
6085
  var module = { exports: exports };
5908
6086
 
5909
6087
  "use strict";
5910
6088
  Object.defineProperty(exports, "__esModule", { value: true });
5911
- exports.IncludeJsParser = void 0;
5912
- const AstUtil_1 = _src_handlers_script_utils_AstUtil;
5913
- const Include_1 = _src_class_Include;
5914
- const ResourcePropMapping_1 = _src_class_ResourcePropMapping;
5915
- const BaseParser_1 = _src_handlers_base_BaseParser;
5916
- const atma_utils_1 = require("atma-utils");
5917
- class IncludeJsParser extends BaseParser_1.BaseParser {
6089
+ exports.CommonJsBuilder = void 0;
6090
+ const CommonJsBuilderSimplified_1 = _src_handlers_script_common_js_CommonJsBuilderSimplified;
6091
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
6092
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6093
+ const template_1 = _src_utils_template;
6094
+ const ModuleWrapper_1 = _src_handlers_script_common_js_ModuleWrapper;
6095
+ class CommonJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5918
6096
  constructor(solution, handler) {
5919
6097
  super(solution, handler);
5920
- if (this.solution.opts.package.module === 'includejs') {
5921
- this.solution.opts.mappers.push(...IncludeJsMappings);
6098
+ this.solution = solution;
6099
+ this.handler = handler;
6100
+ var opts = this.solution.opts.package.commonjs;
6101
+ if (opts && opts.output === 'simplified') {
6102
+ this.wrapModule = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.wrapModule;
6103
+ this.getRootContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getRootContent;
6104
+ this.getHeaderContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getHeaderContent;
5922
6105
  }
5923
6106
  }
5924
- getDependencies(ast, ownerResource) {
5925
- let info = {
5926
- type: null,
5927
- url: null,
5928
- dependencies: [],
5929
- meta: {
5930
- includejs: {
5931
- hasIncludes: false,
5932
- hasExports: false,
5933
- hasResponseObject: false,
5934
- responseAccessors: null,
5935
- }
5936
- }
5937
- };
5938
- AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.includeFunction, (node, descend) => {
5939
- function isIncludeSymbolRef(node) {
5940
- return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
5941
- }
5942
- let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5943
- this._process(info, node, scope);
5944
- return true;
5945
- });
5946
- if (this._getPropertySetter('exports', ast) != null) {
5947
- info.meta.includejs.hasExports = true;
6107
+ accepts(resource) {
6108
+ if (resource.type !== 'js') {
6109
+ return false;
5948
6110
  }
5949
- return new atma_utils_1.class_Dfr().resolve(info);
6111
+ let module = resource.getModule();
6112
+ if (module == null || module === 'root') {
6113
+ module = this.solution.opts.package.module;
6114
+ }
6115
+ return module === 'commonjs';
5950
6116
  }
5951
- _process(info, node, scope) {
5952
- let arr = [];
5953
- function isIncludeMethodCall(node) {
5954
- return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
6117
+ wrapModule(resource, outputItem, outputItems, setts) {
6118
+ var opts = this.solution.iteration;
6119
+ if (opts.commonjs == null) {
6120
+ opts.commonjs = {
6121
+ addHeading: true,
6122
+ hasHeading: false
6123
+ };
5955
6124
  }
5956
6125
  ;
5957
- AstUtil_1.AstUtil.each(node, isIncludeMethodCall, (node) => {
5958
- switch (node.expression && node.expression.property) {
5959
- case 'js':
5960
- case 'css':
5961
- case 'load':
5962
- case 'lazy':
5963
- case 'mask':
5964
- case 'routes':
5965
- case 'setBase':
5966
- case 'cfg':
5967
- let pckg = {
5968
- type: node.expression.property,
5969
- args: AstUtil_1.AstUtil.getArguments(node.args, scope),
5970
- };
5971
- if (pckg.args.length > 0) {
5972
- arr.unshift(pckg);
5973
- }
5974
- info.meta.includejs.hasIncludes = true;
5975
- break;
5976
- case 'done':
5977
- case 'ready':
5978
- this._processIncludeCallback(info, node.args && node.args[0]);
5979
- break;
5980
- case 'instance':
5981
- case 'embed':
5982
- case 'plugin':
5983
- case 'ajax':
5984
- case 'promise':
5985
- case 'client':
5986
- case 'server':
5987
- case 'use':
5988
- case 'getPending':
5989
- case 'getResource':
5990
- case 'getResourceById':
5991
- case 'getResources':
5992
- case 'apply':
5993
- break;
5994
- default:
5995
- this.solution.reporter.warn('getIncludes: Unknown function call', node.expression);
5996
- break;
5997
- }
5998
- });
5999
- let include = new Include_1.Include();
6000
- arr.forEach(function (x) {
6001
- include[x.type].apply(include, x.args);
6002
- });
6003
- info.dependencies.push(...include.includes);
6004
- }
6005
- _processIncludeCallback(info, CallbackNode) {
6006
- if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
6007
- return;
6008
- }
6009
- let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
6010
- ? args[args.length - 1].name
6011
- : null;
6012
- if (responseObjectName) {
6013
- meta.hasResponseObject = true;
6014
- let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
6015
- if (names) {
6016
- meta.responseAccessors = (meta.responseAccessors || []).concat(names);
6017
- }
6126
+ var body = '';
6127
+ if (opts.commonjs.hasHeading === false && opts.commonjs.addHeading === true) {
6128
+ opts.commonjs.hasHeading = true;
6129
+ body = this.getHeaderContent();
6018
6130
  }
6131
+ var { url, content } = resource;
6132
+ var module = Templates_1.Templates
6133
+ .Module
6134
+ .replace('%MODULE_PATH%', () => url)
6135
+ .replace('%MODULE%', () => content)
6136
+ .replace('%FOOTER%', () => { var _a, _b; return ((_b = (_a = setts === null || setts === void 0 ? void 0 : setts.partials) === null || _a === void 0 ? void 0 : _a.footer) !== null && _b !== void 0 ? _b : ''); });
6137
+ return body + module;
6019
6138
  }
6020
- /**
6021
- * resolve %name%.propertyAccessor
6022
- */
6023
- _getPropertyAccessors(name, Fn) {
6024
- let references = [];
6025
- Fn.body.forEach(function (x) {
6026
- function isSymbolName(node) {
6027
- return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
6028
- }
6029
- AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
6030
- let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
6031
- if (chain) {
6032
- references.push(chain);
6033
- }
6034
- });
6035
- });
6036
- return references;
6139
+ getHeaderContent() {
6140
+ var mainUrl = this.solution.outputResources.rootInput.url;
6141
+ return Templates_1.Templates
6142
+ .Header
6143
+ .replace('%ROOT_DIR%', () => mainUrl);
6037
6144
  }
6038
- /**
6039
- * aim to find all **.exports = X
6040
- */
6041
- _getPropertySetter(name, Fn) {
6042
- let result = null;
6043
- Fn.body.forEach(function (x) {
6044
- function isPropertyName(node) {
6045
- AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
6145
+ buildRoot(root, outputDependencies) {
6146
+ outputDependencies.forEach(x => x.embed = true);
6147
+ let content = this.getRootContent(root, outputDependencies);
6148
+ let body = outputDependencies
6149
+ .map(x => {
6150
+ let content = x.content;
6151
+ if (x.type === 'css') {
6152
+ content = (0, template_1.template_interpolate)(Templates_1.Templates.Style, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
6046
6153
  }
6047
- AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
6048
- let arr = ['include', 'module', 'exports'];
6049
- if (arr.indexOf(node.start.value) > -1) {
6050
- result = node;
6051
- }
6052
- });
6053
- });
6054
- return result;
6154
+ if (x.type === 'mask') {
6155
+ content = (0, template_1.template_interpolate)(Templates_1.Templates.Mask, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
6156
+ }
6157
+ return content;
6158
+ })
6159
+ .concat([content])
6160
+ .join('\n');
6161
+ var wrapper = new ModuleWrapper_1.ModuleWrapper(this.solution);
6162
+ root.content = wrapper.wrap(body);
6163
+ }
6164
+ getRootContent(root, outputDependencies) {
6165
+ return root.content;
6055
6166
  }
6056
6167
  }
6057
- exports.IncludeJsParser = IncludeJsParser;
6168
+ exports.CommonJsBuilder = CommonJsBuilder;
6058
6169
  ;
6059
- let IncludeJsMappings = [
6060
- new ResourcePropMapping_1.ResourcePropMapping({
6061
- asModules: (arr) => arr.indexOf('mask') > -1
6062
- }, {
6063
- asModules: (arr) => {
6064
- let i = arr.indexOf('mask');
6065
- arr[i] = 'includejs';
6066
- return arr;
6067
- }
6068
- }),
6069
- new ResourcePropMapping_1.ResourcePropMapping({
6070
- asModules: (arr) => arr.indexOf('amd') > -1
6071
- }, {
6072
- asModules: (arr) => {
6073
- let i = arr.indexOf('amd');
6074
- arr[i] = 'includejs';
6075
- return arr;
6076
- }
6077
- }),
6078
- new ResourcePropMapping_1.ResourcePropMapping({
6079
- type: 'mask'
6080
- }, {
6081
- type: 'load'
6082
- })
6083
- ];
6084
- //# sourceMappingURL=IncludeJsParser.js.map
6085
- //# sourceMappingURL=IncludeJsParser.ts.map;
6170
+ //# sourceMappingURL=CommonJsBuilder.js.map
6171
+ //# sourceMappingURL=CommonJsBuilder.ts.map;
6086
6172
 
6087
6173
  function __isObj(x) {
6088
6174
  return x != null && typeof x === 'object' && x.constructor === Object;
6089
6175
  }
6090
- if (_src_handlers_script_include_js_IncludeJsParser === module.exports) {
6176
+ if (_src_handlers_script_common_js_CommonJsBuilder === module.exports) {
6091
6177
  // do nothing if
6092
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsParser) && __isObj(module.exports)) {
6093
- Object.assign(_src_handlers_script_include_js_IncludeJsParser, module.exports);
6178
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsBuilder) && __isObj(module.exports)) {
6179
+ Object.assign(_src_handlers_script_common_js_CommonJsBuilder, module.exports);
6094
6180
  } else {
6095
- _src_handlers_script_include_js_IncludeJsParser = module.exports;
6181
+ _src_handlers_script_common_js_CommonJsBuilder = module.exports;
6096
6182
  }
6097
6183
 
6098
6184
  ;
@@ -6102,147 +6188,104 @@ let IncludeJsMappings = [
6102
6188
 
6103
6189
 
6104
6190
  // source ./ModuleSimplified.js
6105
- var _src_handlers_script_include_js_IncludeJsBuilder;
6191
+ var _src_handlers_script_common_js_CommonJsPathResolver;
6106
6192
  (function () {
6107
6193
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6108
6194
  var define = null;
6109
- var exports = _src_handlers_script_include_js_IncludeJsBuilder != null ? _src_handlers_script_include_js_IncludeJsBuilder : {};
6195
+ var exports = _src_handlers_script_common_js_CommonJsPathResolver != null ? _src_handlers_script_common_js_CommonJsPathResolver : {};
6110
6196
  var module = { exports: exports };
6111
6197
 
6112
6198
  "use strict";
6113
6199
  Object.defineProperty(exports, "__esModule", { value: true });
6114
- exports.IncludeJsBuilder = void 0;
6115
- const arr_1 = _src_utils_arr;
6116
- const Include_1 = _src_class_Include;
6117
- const res_1 = _src_utils_res;
6118
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6119
- class IncludeJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6120
- wrapScriptlessModule(otherOutputItems) {
6121
- var allResources = (0, arr_1.arr_flattern)(otherOutputItems.map(x => x.resources));
6122
- var jsResources = allResources.filter(x => this.accepts(x));
6123
- var cssResources = allResources.filter(x => x.type === 'css');
6124
- var loadResources = allResources.filter(x => x.type === 'load');
6125
- var jsRegister = this._serializeRegister(jsResources, 'js');
6126
- var cssRegister = this._serializeRegister(cssResources, 'css');
6127
- var loadRegister = this._serializeRegister(loadResources, 'load');
6128
- return `
6129
- ${jsRegister}
6130
- ${cssRegister}
6131
- ${loadRegister}
6132
- `;
6133
- }
6134
- isMainBuilder(solution) {
6135
- const KEY = 'includejs';
6136
- const packageInfo = solution.opts.package;
6137
- return packageInfo.module === KEY || packageInfo.moduleName === KEY;
6138
- }
6139
- wrapModule(resource, outputItem, otherOutputItems) {
6140
- var opts = this.solution.opts;
6141
- var page = (0, res_1.res_getPage)(resource, opts);
6142
- var iteration = this.solution.iteration;
6143
- if (iteration.includejs == null) {
6144
- iteration.includejs = {};
6145
- }
6146
- if (iteration.includejs[page] == null) {
6147
- iteration.includejs[page] = {
6148
- addHeading: true,
6149
- hasHeading: false,
6150
- lastItem: null
6151
- };
6152
- }
6153
- var builderOpts = iteration.includejs[page];
6154
- var body = '';
6155
- if (builderOpts.hasHeading === false && builderOpts.addHeading === true) {
6156
- builderOpts.hasHeading = true;
6157
- body = this._createHeading(builderOpts, resource, outputItem, otherOutputItems);
6200
+ exports.CommonJsPathResolver = void 0;
6201
+ const BasePathResolver_1 = _src_handlers_base_BasePathResolver;
6202
+ const path_1 = _src_utils_path;
6203
+ const global_1 = _src_global;
6204
+ class CommonJsPathResolver extends BasePathResolver_1.BasePathResolver {
6205
+ accepts(includeData) {
6206
+ if (includeData.type !== 'js' || includeData.module !== 'commonjs') {
6207
+ return false;
6158
6208
  }
6159
- let content = resource.content;
6160
- let url = resource.toTargetUrl(this.solution);
6161
- let aliases = resource.aliases == null ? 'null' : '[' + resource.aliases.map(x => `'${x}'`).join(',') + ']';
6162
- body += `include.setCurrent({ url: '${url}', aliases: ${aliases} });\n`;
6163
- body += content;
6164
- body += `\ninclude.getResourceById('${url}', 'js').readystatechanged(3);`;
6165
- if (builderOpts.hasHeading && builderOpts.lastItem === resource) {
6166
- body += `\ninclude.resumeStack();`;
6209
+ if (!/^[\w\-/]+$/.test(includeData.url)) {
6210
+ return false;
6167
6211
  }
6168
- return body;
6169
- }
6170
- accepts(resource) {
6171
- if (resource.type !== 'js') {
6212
+ if (nodeCoreModules.indexOf(includeData.url) !== -1) {
6172
6213
  return false;
6173
6214
  }
6174
- const module = resource.getModule();
6175
- return module === 'includejs';
6176
- }
6177
- _createHeading(builderOpts, resource, outputItem, otherOutputItems) {
6178
- var outputItems = [outputItem, ...otherOutputItems];
6179
- var allResources = (0, arr_1.arr_flattern)(outputItems.map(x => x.resources));
6180
- var jsResources = allResources.filter(x => this.accepts(x));
6181
- var cssResources = allResources.filter(x => x.type === 'css');
6182
- var loadResources = allResources.filter(x => x.type === 'load');
6183
- builderOpts.lastItem = jsResources[jsResources.length - 1];
6184
- var jsRegister = this._serializeRegister(jsResources, 'js');
6185
- var cssRegister = this._serializeRegister(cssResources, 'css');
6186
- var loadRegister = this._serializeRegister(loadResources, 'load');
6187
- var version = this._serializeVersion();
6188
- var config = this._serializeConfig();
6189
- var heading = `
6190
- ${version}
6191
- ${config}
6192
- include.pauseStack();
6193
- ${jsRegister}
6194
- ${cssRegister}
6195
- ${loadRegister}
6196
- `;
6197
- return heading;
6198
- }
6199
- _serializeVersion() {
6200
- var v = this.solution.opts.version;
6201
- if (!v)
6202
- return '';
6203
- return `include.cfg('version', '${v}');`;
6204
- }
6205
- _serializeConfig() {
6206
- var opts = Include_1.Include.getConfig();
6207
- var json = JSON.stringify(opts);
6208
- if (json === '{}')
6209
- return '';
6210
- return `include.cfg(${json});`;
6215
+ return true;
6211
6216
  }
6212
- _serializeRegister(resources, type) {
6213
- var paths = resources
6214
- .filter(x => x.type === type)
6215
- .map(x => {
6216
- return {
6217
- type: type,
6218
- url: x.toTargetUrl(this.solution)
6219
- };
6220
- });
6221
- if (paths.length === 0) {
6222
- return '';
6217
+ resolve(includeData, parentResource) {
6218
+ let filename = nodeModuleResolve(includeData.url, parentResource.directory);
6219
+ if (filename) {
6220
+ let url = this.solution.opts.toAppUrl(filename);
6221
+ this.solution.opts.mappings[includeData.url] = url;
6223
6222
  }
6224
- var json = JSON.stringify({
6225
- [type]: paths
6226
- });
6227
- return `
6228
- include.register(${json});
6229
- `;
6223
+ return filename;
6230
6224
  }
6231
6225
  }
6232
- exports.IncludeJsBuilder = IncludeJsBuilder;
6226
+ exports.CommonJsPathResolver = CommonJsPathResolver;
6233
6227
  ;
6234
- //# sourceMappingURL=IncludeJsBuilder.js.map
6235
- //# sourceMappingURL=IncludeJsBuilder.ts.map;
6236
-
6237
- function __isObj(x) {
6238
- return x != null && typeof x === 'object' && x.constructor === Object;
6239
- }
6240
- if (_src_handlers_script_include_js_IncludeJsBuilder === module.exports) {
6241
- // do nothing if
6242
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsBuilder) && __isObj(module.exports)) {
6243
- Object.assign(_src_handlers_script_include_js_IncludeJsBuilder, module.exports);
6244
- } else {
6245
- _src_handlers_script_include_js_IncludeJsBuilder = module.exports;
6228
+ const nodeCoreModules = [
6229
+ 'assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
6230
+ 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
6231
+ 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
6232
+ 'tls', 'tty', 'url', 'util', 'vm', 'zlib'
6233
+ ];
6234
+ function nodeModuleResolve(path, location_) {
6235
+ let location = location_.replace(/[\\\/]+$/, '');
6236
+ let name = /^([\w\-]+)/.exec(path)[0];
6237
+ let resource = path.substring(name.length + 1);
6238
+ let current = location;
6239
+ let root_ = current + '/node_modules/' + name + '/';
6240
+ while (true) {
6241
+ let nodeModules = (0, path_1.path_combine)(current, '/node_modules/' + name + '/');
6242
+ let pckg = nodeModules + 'package.json';
6243
+ if (global_1.io.File.exists(pckg) === false) {
6244
+ let next = current.replace(/[^\/\\]+[\/\\]?$/, '');
6245
+ if (next === current) {
6246
+ return root_ + 'package.json';
6247
+ }
6248
+ current = next;
6249
+ continue;
6250
+ }
6251
+ if (resource) {
6252
+ let path = nodeModules + resource;
6253
+ if (hasExt(path) === false) {
6254
+ let likelyTs = path.includes('/src/');
6255
+ if (likelyTs) {
6256
+ if (global_1.io.File.exists(path + '.ts')) {
6257
+ return path + '.ts';
6258
+ }
6259
+ }
6260
+ return path + '.js';
6261
+ }
6262
+ return path;
6263
+ }
6264
+ let json = global_1.io.File.read(pckg);
6265
+ if (typeof json === 'string') {
6266
+ json = JSON.parse(json);
6267
+ }
6268
+ if (json.main) {
6269
+ return (0, path_1.path_combine)(nodeModules, json.main);
6270
+ }
6271
+ return nodeModules + 'index.js';
6272
+ }
6273
+ }
6274
+ function hasExt(path) {
6275
+ return /\.[\w]{1,8}($|\?)/.test(path);
6276
+ }
6277
+ //# sourceMappingURL=CommonJsPathResolver.js.map
6278
+ //# sourceMappingURL=CommonJsPathResolver.ts.map;
6279
+
6280
+ function __isObj(x) {
6281
+ return x != null && typeof x === 'object' && x.constructor === Object;
6282
+ }
6283
+ if (_src_handlers_script_common_js_CommonJsPathResolver === module.exports) {
6284
+ // do nothing if
6285
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsPathResolver) && __isObj(module.exports)) {
6286
+ Object.assign(_src_handlers_script_common_js_CommonJsPathResolver, module.exports);
6287
+ } else {
6288
+ _src_handlers_script_common_js_CommonJsPathResolver = module.exports;
6246
6289
  }
6247
6290
 
6248
6291
  ;
@@ -6252,43 +6295,41 @@ exports.IncludeJsBuilder = IncludeJsBuilder;
6252
6295
 
6253
6296
 
6254
6297
  // source ./ModuleSimplified.js
6255
- var _src_handlers_script_include_js_IncludeJsRewriter;
6298
+ var _src_handlers_script_common_js_CommonJsHandler;
6256
6299
  (function () {
6257
6300
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6258
6301
  var define = null;
6259
- var exports = _src_handlers_script_include_js_IncludeJsRewriter != null ? _src_handlers_script_include_js_IncludeJsRewriter : {};
6302
+ var exports = _src_handlers_script_common_js_CommonJsHandler != null ? _src_handlers_script_common_js_CommonJsHandler : {};
6260
6303
  var module = { exports: exports };
6261
6304
 
6262
6305
  "use strict";
6263
6306
  Object.defineProperty(exports, "__esModule", { value: true });
6264
- exports.IncludeJsRewriter = void 0;
6265
- const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6266
- class IncludeJsRewriter extends BaseRewriter_1.BaseRewriter {
6267
- rewritePartial(content, ownerResource) {
6268
- }
6269
- rewriteResource(resource) {
6270
- if (resource.getModule() === 'global' && resource && resource.meta && resource.meta.includejs && resource.meta.includejs.hasIncludes) {
6271
- resource.asModules = ['includejs'];
6272
- }
6273
- }
6274
- accepts(type) {
6275
- return type === 'js';
6276
- }
6307
+ exports.CommonJsHandler = void 0;
6308
+ const CommonJsParser_1 = _src_handlers_script_common_js_CommonJsParser;
6309
+ const CommonJsRewriter_1 = _src_handlers_script_common_js_CommonJsRewriter;
6310
+ const CommonJsBuilder_1 = _src_handlers_script_common_js_CommonJsBuilder;
6311
+ const CommonJsPathResolver_1 = _src_handlers_script_common_js_CommonJsPathResolver;
6312
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
6313
+ class CommonJsHandler extends BaseHandler_1.BaseHandler {
6277
6314
  }
6278
- exports.IncludeJsRewriter = IncludeJsRewriter;
6315
+ exports.CommonJsHandler = CommonJsHandler;
6316
+ CommonJsHandler.Parser = CommonJsParser_1.CommonJsParser;
6317
+ CommonJsHandler.Rewriter = CommonJsRewriter_1.CommonJsRewriter;
6318
+ CommonJsHandler.Builder = CommonJsBuilder_1.CommonJsBuilder;
6319
+ CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
6279
6320
  ;
6280
- //# sourceMappingURL=IncludeJsRewriter.js.map
6281
- //# sourceMappingURL=IncludeJsRewriter.ts.map;
6321
+ //# sourceMappingURL=CommonJsHandler.js.map
6322
+ //# sourceMappingURL=CommonJsHandler.ts.map;
6282
6323
 
6283
6324
  function __isObj(x) {
6284
6325
  return x != null && typeof x === 'object' && x.constructor === Object;
6285
6326
  }
6286
- if (_src_handlers_script_include_js_IncludeJsRewriter === module.exports) {
6327
+ if (_src_handlers_script_common_js_CommonJsHandler === module.exports) {
6287
6328
  // do nothing if
6288
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsRewriter) && __isObj(module.exports)) {
6289
- Object.assign(_src_handlers_script_include_js_IncludeJsRewriter, module.exports);
6329
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsHandler) && __isObj(module.exports)) {
6330
+ Object.assign(_src_handlers_script_common_js_CommonJsHandler, module.exports);
6290
6331
  } else {
6291
- _src_handlers_script_include_js_IncludeJsRewriter = module.exports;
6332
+ _src_handlers_script_common_js_CommonJsHandler = module.exports;
6292
6333
  }
6293
6334
 
6294
6335
  ;
@@ -6298,71 +6339,69 @@ exports.IncludeJsRewriter = IncludeJsRewriter;
6298
6339
 
6299
6340
 
6300
6341
  // source ./ModuleSimplified.js
6301
- var _src_handlers_script_include_js_IncludeJsHandler;
6342
+ var _src_handlers_script_amd_js_AmdJsParser;
6302
6343
  (function () {
6303
6344
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6304
6345
  var define = null;
6305
- var exports = _src_handlers_script_include_js_IncludeJsHandler != null ? _src_handlers_script_include_js_IncludeJsHandler : {};
6346
+ var exports = _src_handlers_script_amd_js_AmdJsParser != null ? _src_handlers_script_amd_js_AmdJsParser : {};
6306
6347
  var module = { exports: exports };
6307
6348
 
6308
6349
  "use strict";
6309
6350
  Object.defineProperty(exports, "__esModule", { value: true });
6310
- exports.IncludeJsHandler = void 0;
6311
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
6351
+ exports.AmdJsParser = void 0;
6352
+ const BaseParser_1 = _src_handlers_base_BaseParser;
6353
+ const AstUtil_1 = _src_handlers_script_utils_AstUtil;
6354
+ const atma_utils_1 = require("atma-utils");
6312
6355
  const Include_1 = _src_class_Include;
6313
- const IncludeJsParser_1 = _src_handlers_script_include_js_IncludeJsParser;
6314
- const IncludeJsBuilder_1 = _src_handlers_script_include_js_IncludeJsBuilder;
6315
- const BaseHandler_1 = _src_handlers_base_BaseHandler;
6316
- const IncludeJsRewriter_1 = _src_handlers_script_include_js_IncludeJsRewriter;
6317
- class IncludeJsHandler extends BaseHandler_1.BaseHandler {
6318
- constructor(solution) {
6319
- super(solution);
6320
- // if (this.solution.opts.package.module === 'includejs') {
6321
- // this.registerMappings_();
6322
- // }
6356
+ class AmdJsParser extends BaseParser_1.BaseParser {
6357
+ getDependencies(ast, ownerResource) {
6358
+ let info = {
6359
+ dependencies: []
6360
+ };
6361
+ AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.amdFunction, (node, descend) => {
6362
+ let scope = node.scope || ast;
6363
+ let deps = this._process(node, scope);
6364
+ if (deps) {
6365
+ info.dependencies.push(...deps);
6366
+ }
6367
+ return true;
6368
+ });
6369
+ return new atma_utils_1.class_Dfr().resolve(info);
6323
6370
  }
6324
- accepts(resource) {
6325
- if (resource.type !== 'js') {
6326
- return false;
6371
+ _process(node, scope) {
6372
+ if (node.args.length < 2) {
6373
+ return;
6327
6374
  }
6328
- var module = resource.getModule();
6329
- if (module == null || module === 'root')
6330
- module = this.solution.opts.package.module;
6331
- return module === 'includejs';
6332
- }
6333
- rewriteRoot(root, dependencies) {
6334
- dependencies.forEach(x => x.embed = true);
6335
- var body = dependencies
6336
- .map(x => x.content)
6337
- .concat([root.content])
6338
- .join('\n');
6339
- body = Templates_1.Templates.RootModule.replace('%BUNDLE%', () => body);
6340
- root.content = body;
6341
- }
6342
- resolvePath(includeData, parent) {
6343
- return Include_1.Include
6344
- .PathResolver
6345
- .resolveBasic(includeData.url, includeData.type, parent);
6375
+ let args = AstUtil_1.AstUtil.getArguments(node.args, scope);
6376
+ let res = new Include_1.Include();
6377
+ let dependencies = args.find(x => Array.isArray(x));
6378
+ if (dependencies == null) {
6379
+ return;
6380
+ }
6381
+ let groups = Include_1.Include.groupByType(dependencies, this.solution.opts);
6382
+ for (let type in groups) {
6383
+ res[type].apply(res, groups[type]);
6384
+ }
6385
+ res.includes.forEach(x => x.module = 'amd');
6386
+ let ignore = ['exports', 'require'];
6387
+ res.includes = res.includes.filter(x => ignore.indexOf(x.url) === -1);
6388
+ return res.includes;
6346
6389
  }
6347
6390
  }
6348
- exports.IncludeJsHandler = IncludeJsHandler;
6349
- IncludeJsHandler.Parser = IncludeJsParser_1.IncludeJsParser;
6350
- IncludeJsHandler.Rewriter = IncludeJsRewriter_1.IncludeJsRewriter;
6351
- IncludeJsHandler.Builder = IncludeJsBuilder_1.IncludeJsBuilder;
6352
- IncludeJsHandler.PathResolver = null;
6391
+ exports.AmdJsParser = AmdJsParser;
6353
6392
  ;
6354
- //# sourceMappingURL=IncludeJsHandler.js.map
6355
- //# sourceMappingURL=IncludeJsHandler.ts.map;
6393
+ //# sourceMappingURL=AmdJsParser.js.map
6394
+ //# sourceMappingURL=AmdJsParser.ts.map;
6356
6395
 
6357
6396
  function __isObj(x) {
6358
6397
  return x != null && typeof x === 'object' && x.constructor === Object;
6359
6398
  }
6360
- if (_src_handlers_script_include_js_IncludeJsHandler === module.exports) {
6399
+ if (_src_handlers_script_amd_js_AmdJsParser === module.exports) {
6361
6400
  // do nothing if
6362
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsHandler) && __isObj(module.exports)) {
6363
- Object.assign(_src_handlers_script_include_js_IncludeJsHandler, module.exports);
6401
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsParser) && __isObj(module.exports)) {
6402
+ Object.assign(_src_handlers_script_amd_js_AmdJsParser, module.exports);
6364
6403
  } else {
6365
- _src_handlers_script_include_js_IncludeJsHandler = module.exports;
6404
+ _src_handlers_script_amd_js_AmdJsParser = module.exports;
6366
6405
  }
6367
6406
 
6368
6407
  ;
@@ -6372,89 +6411,40 @@ IncludeJsHandler.PathResolver = null;
6372
6411
 
6373
6412
 
6374
6413
  // source ./ModuleSimplified.js
6375
- var _src_handlers_script_import_js_utils;
6414
+ var _src_handlers_script_amd_js_AmdJsRewriter;
6376
6415
  (function () {
6377
6416
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6378
6417
  var define = null;
6379
- var exports = _src_handlers_script_import_js_utils != null ? _src_handlers_script_import_js_utils : {};
6418
+ var exports = _src_handlers_script_amd_js_AmdJsRewriter != null ? _src_handlers_script_amd_js_AmdJsRewriter : {};
6380
6419
  var module = { exports: exports };
6381
6420
 
6382
6421
  "use strict";
6383
6422
  Object.defineProperty(exports, "__esModule", { value: true });
6384
- exports.u_asString = exports.u_readFile = exports.u_getFilesFromPath = exports.u_makeIndent = exports.u_getIndent = exports.u_getNewLine = void 0;
6385
- function u_getNewLine(str, io) {
6386
- var match = /(\r\n)|(\r)|(\n)/.exec(str);
6387
- return (match && match[0]) || io.env.newLine;
6388
- }
6389
- exports.u_getNewLine = u_getNewLine;
6390
- ;
6391
- function u_getIndent(str) {
6392
- var match = /^[ \t]+/.exec(str);
6393
- return match && match[0] || '';
6394
- }
6395
- exports.u_getIndent = u_getIndent;
6396
- ;
6397
- function u_makeIndent(str, indent, io) {
6398
- if (!indent || !str)
6399
- return str;
6400
- let newline = u_getNewLine(str, io);
6401
- return str
6402
- .split(newline)
6403
- .map(line => indent + line)
6404
- .join(newline);
6405
- }
6406
- exports.u_makeIndent = u_makeIndent;
6407
- ;
6408
- function u_getFilesFromPath(path, io) {
6409
- var file = new io.File(path);
6410
- if (file.exists() === false) {
6411
- console.error('File not found', file.uri.toLocalFile());
6412
- return [];
6423
+ exports.AmdJsRewriter = void 0;
6424
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6425
+ class AmdJsRewriter extends BaseRewriter_1.BaseRewriter {
6426
+ rewritePartial(content, ownerResource) {
6413
6427
  }
6414
- return [file];
6415
- }
6416
- exports.u_getFilesFromPath = u_getFilesFromPath;
6417
- ;
6418
- function u_readFile(io, file, indent, insertFileName) {
6419
- var content = file.read().toString();
6420
- var newline = u_getNewLine(content, io);
6421
- if (indent) {
6422
- content = content
6423
- .split(newline)
6424
- .map(line => indent + line)
6425
- .join(newline);
6428
+ rewriteResource(resource) {
6426
6429
  }
6427
- if (insertFileName) {
6428
- content = indent
6429
- + '// source '
6430
- + file.uri.file
6431
- + newline
6432
- + content;
6430
+ accepts(type) {
6431
+ return type === 'mask';
6433
6432
  }
6434
- return content;
6435
6433
  }
6436
- exports.u_readFile = u_readFile;
6434
+ exports.AmdJsRewriter = AmdJsRewriter;
6437
6435
  ;
6438
- function u_asString(str) {
6439
- str = str
6440
- .replace(/[\n\r]/g, '\\n')
6441
- .replace(/"/g, '\\"');
6442
- return `"${str}"`;
6443
- }
6444
- exports.u_asString = u_asString;
6445
- ;
6446
- //# sourceMappingURL=utils.js.map
6447
- //# sourceMappingURL=utils.ts.map;
6436
+ //# sourceMappingURL=AmdJsRewriter.js.map
6437
+ //# sourceMappingURL=AmdJsRewriter.ts.map;
6448
6438
 
6449
6439
  function __isObj(x) {
6450
6440
  return x != null && typeof x === 'object' && x.constructor === Object;
6451
6441
  }
6452
- if (_src_handlers_script_import_js_utils === module.exports) {
6442
+ if (_src_handlers_script_amd_js_AmdJsRewriter === module.exports) {
6453
6443
  // do nothing if
6454
- } else if (__isObj(_src_handlers_script_import_js_utils) && __isObj(module.exports)) {
6455
- Object.assign(_src_handlers_script_import_js_utils, module.exports);
6444
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsRewriter) && __isObj(module.exports)) {
6445
+ Object.assign(_src_handlers_script_amd_js_AmdJsRewriter, module.exports);
6456
6446
  } else {
6457
- _src_handlers_script_import_js_utils = module.exports;
6447
+ _src_handlers_script_amd_js_AmdJsRewriter = module.exports;
6458
6448
  }
6459
6449
 
6460
6450
  ;
@@ -6464,107 +6454,48 @@ exports.u_asString = u_asString;
6464
6454
 
6465
6455
 
6466
6456
  // source ./ModuleSimplified.js
6467
- var _src_handlers_script_import_js_Dictionary;
6457
+ var _src_handlers_script_amd_js_AmdJsBuilder;
6468
6458
  (function () {
6469
6459
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6470
6460
  var define = null;
6471
- var exports = _src_handlers_script_import_js_Dictionary != null ? _src_handlers_script_import_js_Dictionary : {};
6461
+ var exports = _src_handlers_script_amd_js_AmdJsBuilder != null ? _src_handlers_script_amd_js_AmdJsBuilder : {};
6472
6462
  var module = { exports: exports };
6473
6463
 
6474
6464
  "use strict";
6475
6465
  Object.defineProperty(exports, "__esModule", { value: true });
6476
- exports.Dictionary = void 0;
6477
- class Dictionary {
6478
- constructor() {
6479
- this.hash = {};
6480
- this.arr = [];
6481
- }
6482
- add(...arr) {
6483
- for (let i = 0; i < arr.length; i++) {
6484
- let x = arr[i];
6485
- if (this.hash[x.id] != null) {
6486
- continue;
6487
- }
6488
- this.hash[x.id] = x;
6489
- this.arr.push(x);
6490
- }
6491
- }
6492
- insert(x, i) {
6493
- if (this.hash[x.id] != null) {
6494
- this.remove(x);
6495
- }
6496
- this.hash[x.id] = x;
6497
- this.arr.splice(i, 0, x);
6498
- }
6499
- has(x) {
6500
- return this.hash[x.id] != null;
6501
- }
6502
- indexOf(x) {
6503
- for (let i = 0; i < this.arr.length; i++) {
6504
- if (this.arr[i].id === x.id) {
6505
- return i;
6506
- }
6507
- }
6508
- return -1;
6466
+ exports.AmdJsBuilder = void 0;
6467
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6468
+ class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6469
+ buildRoot(resource, dependencies) {
6509
6470
  }
6510
- remove(x) {
6511
- delete this.hash[x.id];
6512
- let i = this.arr.findIndex(module => module.id === x.id);
6513
- this.arr.splice(i, 1);
6471
+ wrapModule(resource, outputItem) {
6472
+ return resource.content;
6514
6473
  }
6515
- removeByFn(fn) {
6516
- let handled = new Dictionary();
6517
- while (true) {
6518
- let i = -1, length = this.arr.length;
6519
- while (++i < length) {
6520
- let x = this.arr[i];
6521
- if (handled.has(x)) {
6522
- continue;
6523
- }
6524
- handled.add(x);
6525
- if (fn(x)) {
6526
- this.arr.splice(i, 1);
6527
- delete this.hash[x.id];
6528
- }
6529
- break;
6530
- }
6531
- if (i === length) {
6532
- break;
6533
- }
6474
+ accepts(resource) {
6475
+ if (resource.type !== 'js') {
6476
+ return false;
6534
6477
  }
6535
- }
6536
- forEach(fn) {
6537
- let handled = new Dictionary();
6538
- while (true) {
6539
- let i = -1, length = this.arr.length;
6540
- while (++i < length) {
6541
- let x = this.arr[i];
6542
- if (handled.has(x)) {
6543
- continue;
6544
- }
6545
- handled.add(x);
6546
- fn(x, i);
6547
- break;
6548
- }
6549
- if (i === length) {
6550
- break;
6551
- }
6478
+ let module = resource.getModule();
6479
+ if (module === 'root' && resource.solution.opts.package.module === 'amd') {
6480
+ module = 'amd';
6552
6481
  }
6482
+ return module === 'amd';
6553
6483
  }
6554
6484
  }
6555
- exports.Dictionary = Dictionary;
6556
- //# sourceMappingURL=Dictionary.js.map
6557
- //# sourceMappingURL=Dictionary.ts.map;
6485
+ exports.AmdJsBuilder = AmdJsBuilder;
6486
+ ;
6487
+ //# sourceMappingURL=AmdJsBuilder.js.map
6488
+ //# sourceMappingURL=AmdJsBuilder.ts.map;
6558
6489
 
6559
6490
  function __isObj(x) {
6560
6491
  return x != null && typeof x === 'object' && x.constructor === Object;
6561
6492
  }
6562
- if (_src_handlers_script_import_js_Dictionary === module.exports) {
6493
+ if (_src_handlers_script_amd_js_AmdJsBuilder === module.exports) {
6563
6494
  // do nothing if
6564
- } else if (__isObj(_src_handlers_script_import_js_Dictionary) && __isObj(module.exports)) {
6565
- Object.assign(_src_handlers_script_import_js_Dictionary, module.exports);
6495
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsBuilder) && __isObj(module.exports)) {
6496
+ Object.assign(_src_handlers_script_amd_js_AmdJsBuilder, module.exports);
6566
6497
  } else {
6567
- _src_handlers_script_import_js_Dictionary = module.exports;
6498
+ _src_handlers_script_amd_js_AmdJsBuilder = module.exports;
6568
6499
  }
6569
6500
 
6570
6501
  ;
@@ -6574,35 +6505,40 @@ exports.Dictionary = Dictionary;
6574
6505
 
6575
6506
 
6576
6507
  // source ./ModuleSimplified.js
6577
- var _src_handlers_script_import_js_String;
6508
+ var _src_handlers_script_amd_js_AmdJsHandler;
6578
6509
  (function () {
6579
6510
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6580
6511
  var define = null;
6581
- var exports = _src_handlers_script_import_js_String != null ? _src_handlers_script_import_js_String : {};
6512
+ var exports = _src_handlers_script_amd_js_AmdJsHandler != null ? _src_handlers_script_amd_js_AmdJsHandler : {};
6582
6513
  var module = { exports: exports };
6583
6514
 
6584
6515
  "use strict";
6585
6516
  Object.defineProperty(exports, "__esModule", { value: true });
6586
- exports.String = void 0;
6587
- var String;
6588
- (function (String) {
6589
- function replace(str, i, length, ins = '') {
6590
- return str.substring(0, i) + ins + str.substring(i + length);
6591
- }
6592
- String.replace = replace;
6593
- })(String = exports.String || (exports.String = {}));
6594
- //# sourceMappingURL=String.js.map
6595
- //# sourceMappingURL=String.ts.map;
6517
+ exports.AmdJsHandler = void 0;
6518
+ const AmdJsParser_1 = _src_handlers_script_amd_js_AmdJsParser;
6519
+ const AmdJsRewriter_1 = _src_handlers_script_amd_js_AmdJsRewriter;
6520
+ const AmdJsBuilder_1 = _src_handlers_script_amd_js_AmdJsBuilder;
6521
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
6522
+ class AmdJsHandler extends BaseHandler_1.BaseHandler {
6523
+ }
6524
+ exports.AmdJsHandler = AmdJsHandler;
6525
+ AmdJsHandler.Parser = AmdJsParser_1.AmdJsParser;
6526
+ AmdJsHandler.Rewriter = AmdJsRewriter_1.AmdJsRewriter;
6527
+ AmdJsHandler.Builder = AmdJsBuilder_1.AmdJsBuilder;
6528
+ AmdJsHandler.PathResolver = null;
6529
+ ;
6530
+ //# sourceMappingURL=AmdJsHandler.js.map
6531
+ //# sourceMappingURL=AmdJsHandler.ts.map;
6596
6532
 
6597
6533
  function __isObj(x) {
6598
6534
  return x != null && typeof x === 'object' && x.constructor === Object;
6599
6535
  }
6600
- if (_src_handlers_script_import_js_String === module.exports) {
6536
+ if (_src_handlers_script_amd_js_AmdJsHandler === module.exports) {
6601
6537
  // do nothing if
6602
- } else if (__isObj(_src_handlers_script_import_js_String) && __isObj(module.exports)) {
6603
- Object.assign(_src_handlers_script_import_js_String, module.exports);
6538
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsHandler) && __isObj(module.exports)) {
6539
+ Object.assign(_src_handlers_script_amd_js_AmdJsHandler, module.exports);
6604
6540
  } else {
6605
- _src_handlers_script_import_js_String = module.exports;
6541
+ _src_handlers_script_amd_js_AmdJsHandler = module.exports;
6606
6542
  }
6607
6543
 
6608
6544
  ;
@@ -6612,255 +6548,469 @@ var String;
6612
6548
 
6613
6549
 
6614
6550
  // source ./ModuleSimplified.js
6615
- var _src_handlers_script_import_js_ModuleFile;
6551
+ var _src_class_ResourcePropMapping;
6616
6552
  (function () {
6617
6553
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6618
6554
  var define = null;
6619
- var exports = _src_handlers_script_import_js_ModuleFile != null ? _src_handlers_script_import_js_ModuleFile : {};
6555
+ var exports = _src_class_ResourcePropMapping != null ? _src_class_ResourcePropMapping : {};
6620
6556
  var module = { exports: exports };
6621
6557
 
6622
6558
  "use strict";
6623
6559
  Object.defineProperty(exports, "__esModule", { value: true });
6624
- exports.ModuleFile = exports.IImporterOptions = void 0;
6625
- const io = require("atma-io");
6626
- const utils_1 = _src_handlers_script_import_js_utils;
6627
- const Dictionary_1 = _src_handlers_script_import_js_Dictionary;
6628
- const String_1 = _src_handlers_script_import_js_String;
6629
- class IImporterOptions {
6630
- constructor() {
6631
- this.removeUnusedExports = true;
6632
- this.wrapper = 'iif';
6633
- this.lazy = null;
6634
- }
6635
- }
6636
- exports.IImporterOptions = IImporterOptions;
6637
- class ModuleFile {
6638
- constructor(content, file) {
6639
- this.content = content;
6640
- this.file = file;
6641
- this.outer = new Dictionary_1.Dictionary();
6642
- this.scoped = new Dictionary_1.Dictionary();
6643
- this.imports = [];
6644
- this.exports = [];
6645
- this.scopedVars = [];
6646
- this.id = file.uri.toLocalFile();
6647
- this.path = file.uri.toRelativeString(io.env.currentDir);
6560
+ exports.ResourcePropMapping = void 0;
6561
+ class ResourcePropMapping {
6562
+ constructor(resA, resB) {
6563
+ this.resA = resA;
6564
+ this.resB = resB;
6648
6565
  }
6649
- hasDeep(x, ignore, hash = new Dictionary_1.Dictionary()) {
6650
- function check(arr) {
6651
- for (let i = 0; i < arr.length; i++) {
6652
- let module = arr[i];
6653
- if (module == ignore || hash.has(module)) {
6654
- continue;
6655
- }
6656
- hash.add(module);
6657
- let has = module.hasDeep(x, ignore, hash);
6658
- if (has) {
6659
- return true;
6660
- }
6566
+ map(resource) {
6567
+ let match = true;
6568
+ for (let key in this.resA) {
6569
+ let val = this.resA[key];
6570
+ if (val == null)
6571
+ continue;
6572
+ let currentVal = resource[key];
6573
+ if (typeof val === 'function') {
6574
+ match = val(currentVal);
6575
+ }
6576
+ if (val instanceof RegExp) {
6577
+ match = val.exec(currentVal) != null;
6578
+ }
6579
+ if (typeof val === 'string' || typeof val === 'number') {
6580
+ match = val === currentVal;
6581
+ }
6582
+ if (match == false) {
6583
+ return resource;
6661
6584
  }
6662
- return false;
6663
- }
6664
- if (this.id === x.id) {
6665
- return true;
6666
6585
  }
6667
- return check(this.outer.arr) || check(this.scoped.arr);
6668
- }
6669
- getAllModules() {
6670
- let dict = new Dictionary_1.Dictionary();
6671
- function add(module) {
6672
- if (dict.has(module)) {
6673
- return;
6586
+ let clone = resource.clone();
6587
+ for (let key in this.resB) {
6588
+ let val = this.resB[key];
6589
+ let currentVal = resource[key];
6590
+ if (typeof val === 'function') {
6591
+ clone[key] = val(currentVal, resource);
6592
+ continue;
6593
+ }
6594
+ if (typeof val === 'string' || typeof val === 'boolean') {
6595
+ clone[key] = val;
6596
+ continue;
6674
6597
  }
6675
- dict.add(module);
6676
- module.outer.forEach(add);
6677
- module.scoped.forEach(add);
6678
6598
  }
6679
- add(this);
6680
- return dict.arr;
6599
+ return clone;
6681
6600
  }
6682
- static getAllImports(modules) {
6683
- let arr = [];
6684
- modules.filter(x => x.imports != null).forEach(x => arr.push(...x.imports));
6685
- return arr;
6686
- // function read (module: ModuleFile, stack: ModuleFile[] = []): ImportNode[] {
6687
- // if (stack.includes(module) || module.imports == null) {
6688
- // return [];
6689
- // }
6690
- // stack.push(module);
6691
- // let arr = [...module.imports];
6692
- // module.imports.forEach(x => arr.push(...read(x.module, stack)));
6693
- // return arr;
6694
- // }
6695
- // return read(this);
6696
- }
6697
- toScript(parents = [], options, indent = '') {
6698
- let newLine = (0, utils_1.u_getNewLine)(this.content, io);
6699
- let outerContent = this
6700
- .outer
6701
- .arr
6702
- .map(x => x.toScript([...parents, this], options))
6703
- .map(x => x.replace(/[\s]*$/, ''))
6704
- .join(newLine);
6705
- let scopedContent = this
6706
- .scoped
6707
- .arr
6708
- .map(x => x.toScript([...parents, this], options))
6709
- .map(x => x.replace(/[\s]*$/, ''))
6710
- .join(newLine);
6711
- let scopedRefs = this
6712
- .scopedVars
6713
- .filter(x => !options.removeUnusedExports || x.dependents.length > 0)
6714
- .map(x => ` ${x.ref}`)
6715
- .join(`,${newLine}`);
6716
- if (scopedRefs) {
6717
- scopedRefs = String_1.String.replace(scopedRefs, 0, 3, 'var');
6718
- scopedRefs += ';';
6719
- scopedContent = scopedRefs + newLine + scopedContent;
6601
+ }
6602
+ exports.ResourcePropMapping = ResourcePropMapping;
6603
+ //# sourceMappingURL=ResourcePropMapping.js.map
6604
+ //# sourceMappingURL=ResourcePropMapping.ts.map;
6605
+
6606
+ function __isObj(x) {
6607
+ return x != null && typeof x === 'object' && x.constructor === Object;
6608
+ }
6609
+ if (_src_class_ResourcePropMapping === module.exports) {
6610
+ // do nothing if
6611
+ } else if (__isObj(_src_class_ResourcePropMapping) && __isObj(module.exports)) {
6612
+ Object.assign(_src_class_ResourcePropMapping, module.exports);
6613
+ } else {
6614
+ _src_class_ResourcePropMapping = module.exports;
6615
+ }
6616
+
6617
+ ;
6618
+ }());
6619
+
6620
+ // end:source ./ModuleSimplified.js
6621
+
6622
+
6623
+ // source ./ModuleSimplified.js
6624
+ var _src_handlers_script_include_js_IncludeJsParser;
6625
+ (function () {
6626
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6627
+ var define = null;
6628
+ var exports = _src_handlers_script_include_js_IncludeJsParser != null ? _src_handlers_script_include_js_IncludeJsParser : {};
6629
+ var module = { exports: exports };
6630
+
6631
+ "use strict";
6632
+ Object.defineProperty(exports, "__esModule", { value: true });
6633
+ exports.IncludeJsParser = void 0;
6634
+ const AstUtil_1 = _src_handlers_script_utils_AstUtil;
6635
+ const Include_1 = _src_class_Include;
6636
+ const ResourcePropMapping_1 = _src_class_ResourcePropMapping;
6637
+ const BaseParser_1 = _src_handlers_base_BaseParser;
6638
+ const atma_utils_1 = require("atma-utils");
6639
+ class IncludeJsParser extends BaseParser_1.BaseParser {
6640
+ constructor(solution, handler) {
6641
+ super(solution, handler);
6642
+ if (this.solution.opts.package.module === 'includejs') {
6643
+ this.solution.opts.mappers.push(...IncludeJsMappings);
6720
6644
  }
6721
- let content = this.content;
6722
- // normalize exports
6723
- this.exports.reverse().forEach(x => {
6724
- if (options.removeUnusedExports && x.dependents.length === 0) {
6725
- let str = content.substring(x.position, x.position + x.length);
6726
- str = str.replace(/\s*export\s*/g, '');
6727
- content = String_1.String.replace(content, x.position, x.length, str);
6728
- return;
6645
+ }
6646
+ getDependencies(ast, ownerResource) {
6647
+ let info = {
6648
+ type: null,
6649
+ url: null,
6650
+ dependencies: [],
6651
+ meta: {
6652
+ includejs: {
6653
+ hasIncludes: false,
6654
+ hasExports: false,
6655
+ hasResponseObject: false,
6656
+ responseAccessors: null,
6657
+ }
6729
6658
  }
6730
- switch (x.type) {
6731
- case 'ref':
6732
- content = String_1.String.replace(content, x.position, x.length, x.ref);
6659
+ };
6660
+ AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.includeFunction, (node, descend) => {
6661
+ function isIncludeSymbolRef(node) {
6662
+ return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
6663
+ }
6664
+ let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
6665
+ this._process(info, node, scope);
6666
+ return true;
6667
+ });
6668
+ if (this._getPropertySetter('exports', ast) != null) {
6669
+ info.meta.includejs.hasExports = true;
6670
+ }
6671
+ return new atma_utils_1.class_Dfr().resolve(info);
6672
+ }
6673
+ _process(info, node, scope) {
6674
+ let arr = [];
6675
+ function isIncludeMethodCall(node) {
6676
+ return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
6677
+ }
6678
+ ;
6679
+ AstUtil_1.AstUtil.each(node, isIncludeMethodCall, (node) => {
6680
+ switch (node.expression && node.expression.property) {
6681
+ case 'js':
6682
+ case 'css':
6683
+ case 'load':
6684
+ case 'lazy':
6685
+ case 'mask':
6686
+ case 'routes':
6687
+ case 'setBase':
6688
+ case 'cfg':
6689
+ let pckg = {
6690
+ type: node.expression.property,
6691
+ args: AstUtil_1.AstUtil.getArguments(node.args, scope),
6692
+ };
6693
+ if (pckg.args.length > 0) {
6694
+ arr.unshift(pckg);
6695
+ }
6696
+ info.meta.includejs.hasIncludes = true;
6733
6697
  break;
6734
- case 'function':
6735
- content = String_1.String.replace(content, x.position, x.length, `${x.ref} = function `);
6698
+ case 'done':
6699
+ case 'ready':
6700
+ this._processIncludeCallback(info, node.args && node.args[0]);
6736
6701
  break;
6737
- case 'named':
6738
- content = String_1.String.replace(content, x.position, x.length, '');
6702
+ case 'instance':
6703
+ case 'embed':
6704
+ case 'plugin':
6705
+ case 'ajax':
6706
+ case 'promise':
6707
+ case 'client':
6708
+ case 'server':
6709
+ case 'use':
6710
+ case 'getPending':
6711
+ case 'getResource':
6712
+ case 'getResourceById':
6713
+ case 'getResources':
6714
+ case 'apply':
6739
6715
  break;
6740
- case 'scoped':
6741
- if (x.length > 0) {
6742
- content = String_1.String.replace(content, x.position, x.length, '');
6743
- }
6716
+ default:
6717
+ this.solution.reporter.warn('getIncludes: Unknown function call', node.expression);
6744
6718
  break;
6745
6719
  }
6746
6720
  });
6747
- // remove imports
6748
- this.imports.reverse().forEach(x => {
6749
- content = String_1.String.replace(content, x.position, x.length, '');
6721
+ let include = new Include_1.Include();
6722
+ arr.forEach(function (x) {
6723
+ include[x.type].apply(include, x.args);
6750
6724
  });
6751
- // create var declaration
6752
- let externalRefs = '';
6753
- if (this.exports.length > 0) {
6754
- this
6755
- .exports
6756
- .filter(x => {
6757
- return x.dependents.length > 0 || options.removeUnusedExports === false;
6758
- })
6759
- .forEach(x => {
6760
- /** Remove local scoped var declaration and make it global scoped */
6761
- if (x.type === 'scoped') {
6762
- let rgx = new RegExp(`\\b(var|let|const|function)\\s+${x.ref}`);
6763
- content = content.replace(rgx, x.ref);
6725
+ info.dependencies.push(...include.includes);
6726
+ }
6727
+ _processIncludeCallback(info, CallbackNode) {
6728
+ if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
6729
+ return;
6730
+ }
6731
+ let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
6732
+ ? args[args.length - 1].name
6733
+ : null;
6734
+ if (responseObjectName) {
6735
+ meta.hasResponseObject = true;
6736
+ let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
6737
+ if (names) {
6738
+ meta.responseAccessors = (meta.responseAccessors || []).concat(names);
6739
+ }
6740
+ }
6741
+ }
6742
+ /**
6743
+ * resolve %name%.propertyAccessor
6744
+ */
6745
+ _getPropertyAccessors(name, Fn) {
6746
+ let references = [];
6747
+ Fn.body.forEach(function (x) {
6748
+ function isSymbolName(node) {
6749
+ return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
6750
+ }
6751
+ AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
6752
+ let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
6753
+ if (chain) {
6754
+ references.push(chain);
6764
6755
  }
6765
- return x;
6766
6756
  });
6767
- externalRefs = this
6768
- .exports
6769
- .reverse()
6770
- .filter(x => {
6771
- if (x.builder.movedToOuter) {
6772
- return false;
6773
- }
6774
- if (options.removeUnusedExports === false) {
6775
- return true;
6776
- }
6777
- if (x.dependents.length === 0) {
6778
- console.warn(`Module ${this.id} has unused export ${x.ref}`);
6779
- return false;
6780
- }
6781
- return true;
6782
- })
6783
- .filter(x => {
6784
- let exportInOuter = parents
6785
- .some(p => {
6786
- let parentsExport = p.exports.find(e => e.hasExport(x.ref));
6787
- if (parentsExport == null) {
6788
- return false;
6789
- }
6790
- if (options.removeUnusedExports && parentsExport.dependents.length === 0) {
6791
- return false;
6792
- }
6793
- return true;
6794
- });
6795
- return exportInOuter === false;
6796
- })
6797
- .map(x => ` ${x.ref}`)
6798
- .join(`,${newLine}`);
6799
- if (externalRefs.length > 0) {
6800
- externalRefs = String_1.String.replace(externalRefs, 0, 3, 'var');
6801
- externalRefs += ';';
6757
+ });
6758
+ return references;
6759
+ }
6760
+ /**
6761
+ * aim to find all **.exports = X
6762
+ */
6763
+ _getPropertySetter(name, Fn) {
6764
+ let result = null;
6765
+ Fn.body.forEach(function (x) {
6766
+ function isPropertyName(node) {
6767
+ AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
6802
6768
  }
6769
+ AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
6770
+ let arr = ['include', 'module', 'exports'];
6771
+ if (arr.indexOf(node.start.value) > -1) {
6772
+ result = node;
6773
+ }
6774
+ });
6775
+ });
6776
+ return result;
6777
+ }
6778
+ }
6779
+ exports.IncludeJsParser = IncludeJsParser;
6780
+ ;
6781
+ let IncludeJsMappings = [
6782
+ new ResourcePropMapping_1.ResourcePropMapping({
6783
+ asModules: (arr) => arr.indexOf('mask') > -1
6784
+ }, {
6785
+ asModules: (arr) => {
6786
+ let i = arr.indexOf('mask');
6787
+ arr[i] = 'includejs';
6788
+ return arr;
6803
6789
  }
6804
- const SPACE = '\t';
6805
- let indentScopedContent = `${(0, utils_1.u_makeIndent)(scopedContent || '', SPACE, io)}`;
6806
- let indentContent = `${(0, utils_1.u_makeIndent)(content, SPACE, io)}`;
6807
- let scopeLess = parents.length === 0 && options.wrapper !== 'iif';
6808
- content = [
6809
- `${outerContent}` || '',
6810
- `${externalRefs}` || '',
6811
- !scopeLess && (indentScopedContent || indentContent) ? `(function(){` : '',
6812
- indentScopedContent,
6813
- indentContent,
6814
- !scopeLess && (indentScopedContent || indentContent) ? `}());` : ''
6815
- ]
6816
- .filter(x => !!x)
6817
- .join(newLine);
6818
- return (0, utils_1.u_makeIndent)(content, indent, io);
6790
+ }),
6791
+ new ResourcePropMapping_1.ResourcePropMapping({
6792
+ asModules: (arr) => arr.indexOf('amd') > -1
6793
+ }, {
6794
+ asModules: (arr) => {
6795
+ let i = arr.indexOf('amd');
6796
+ arr[i] = 'includejs';
6797
+ return arr;
6798
+ }
6799
+ }),
6800
+ new ResourcePropMapping_1.ResourcePropMapping({
6801
+ type: 'mask'
6802
+ }, {
6803
+ type: 'load'
6804
+ })
6805
+ ];
6806
+ //# sourceMappingURL=IncludeJsParser.js.map
6807
+ //# sourceMappingURL=IncludeJsParser.ts.map;
6808
+
6809
+ function __isObj(x) {
6810
+ return x != null && typeof x === 'object' && x.constructor === Object;
6811
+ }
6812
+ if (_src_handlers_script_include_js_IncludeJsParser === module.exports) {
6813
+ // do nothing if
6814
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsParser) && __isObj(module.exports)) {
6815
+ Object.assign(_src_handlers_script_include_js_IncludeJsParser, module.exports);
6816
+ } else {
6817
+ _src_handlers_script_include_js_IncludeJsParser = module.exports;
6818
+ }
6819
+
6820
+ ;
6821
+ }());
6822
+
6823
+ // end:source ./ModuleSimplified.js
6824
+
6825
+
6826
+ // source ./ModuleSimplified.js
6827
+ var _src_handlers_script_include_js_IncludeJsBuilder;
6828
+ (function () {
6829
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6830
+ var define = null;
6831
+ var exports = _src_handlers_script_include_js_IncludeJsBuilder != null ? _src_handlers_script_include_js_IncludeJsBuilder : {};
6832
+ var module = { exports: exports };
6833
+
6834
+ "use strict";
6835
+ Object.defineProperty(exports, "__esModule", { value: true });
6836
+ exports.IncludeJsBuilder = void 0;
6837
+ const arr_1 = _src_utils_arr;
6838
+ const Include_1 = _src_class_Include;
6839
+ const res_1 = _src_utils_res;
6840
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6841
+ class IncludeJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6842
+ wrapScriptlessModule(otherOutputItems) {
6843
+ var allResources = (0, arr_1.arr_flattern)(otherOutputItems.map(x => x.resources));
6844
+ var jsResources = allResources.filter(x => this.accepts(x));
6845
+ var cssResources = allResources.filter(x => x.type === 'css');
6846
+ var loadResources = allResources.filter(x => x.type === 'load');
6847
+ var jsRegister = this._serializeRegister(jsResources, 'js');
6848
+ var cssRegister = this._serializeRegister(cssResources, 'css');
6849
+ var loadRegister = this._serializeRegister(loadResources, 'load');
6850
+ return `
6851
+ ${jsRegister}
6852
+ ${cssRegister}
6853
+ ${loadRegister}
6854
+ `;
6819
6855
  }
6820
- toImportsJson() {
6821
- function toJSON(module) {
6822
- var json = {
6823
- id: module.id,
6824
- imports: null
6856
+ isMainBuilder(solution) {
6857
+ const KEY = 'includejs';
6858
+ const packageInfo = solution.opts.package;
6859
+ return packageInfo.module === KEY || packageInfo.moduleName === KEY;
6860
+ }
6861
+ wrapModule(resource, outputItem, otherOutputItems) {
6862
+ var opts = this.solution.opts;
6863
+ var page = (0, res_1.res_getPage)(resource, opts);
6864
+ var iteration = this.solution.iteration;
6865
+ if (iteration.includejs == null) {
6866
+ iteration.includejs = {};
6867
+ }
6868
+ if (iteration.includejs[page] == null) {
6869
+ iteration.includejs[page] = {
6870
+ addHeading: true,
6871
+ hasHeading: false,
6872
+ lastItem: null
6825
6873
  };
6826
- if (module.imports) {
6827
- json.imports = module.imports.map(x => toJSON(x.module));
6828
- }
6829
- return json;
6830
6874
  }
6831
- return toJSON(this);
6875
+ var builderOpts = iteration.includejs[page];
6876
+ var body = '';
6877
+ if (builderOpts.hasHeading === false && builderOpts.addHeading === true) {
6878
+ builderOpts.hasHeading = true;
6879
+ body = this._createHeading(builderOpts, resource, outputItem, otherOutputItems);
6880
+ }
6881
+ let content = resource.content;
6882
+ let url = resource.toTargetUrl(this.solution);
6883
+ let aliases = resource.aliases == null ? 'null' : '[' + resource.aliases.map(x => `'${x}'`).join(',') + ']';
6884
+ body += `include.setCurrent({ url: '${url}', aliases: ${aliases} });\n`;
6885
+ body += content;
6886
+ body += `\ninclude.getResourceById('${url}', 'js').readystatechanged(3);`;
6887
+ if (builderOpts.hasHeading && builderOpts.lastItem === resource) {
6888
+ body += `\ninclude.resumeStack();`;
6889
+ }
6890
+ return body;
6832
6891
  }
6833
- toModulesJson() {
6834
- function toJSON(module) {
6835
- let json = {
6836
- id: module.id,
6837
- outer: module.outer.arr.map(x => toJSON(x)),
6838
- scoped: module.scoped.arr.map(x => toJSON(x))
6892
+ accepts(resource) {
6893
+ if (resource.type !== 'js') {
6894
+ return false;
6895
+ }
6896
+ const module = resource.getModule();
6897
+ return module === 'includejs';
6898
+ }
6899
+ _createHeading(builderOpts, resource, outputItem, otherOutputItems) {
6900
+ var outputItems = [outputItem, ...otherOutputItems];
6901
+ var allResources = (0, arr_1.arr_flattern)(outputItems.map(x => x.resources));
6902
+ var jsResources = allResources.filter(x => this.accepts(x));
6903
+ var cssResources = allResources.filter(x => x.type === 'css');
6904
+ var loadResources = allResources.filter(x => x.type === 'load');
6905
+ builderOpts.lastItem = jsResources[jsResources.length - 1];
6906
+ var jsRegister = this._serializeRegister(jsResources, 'js');
6907
+ var cssRegister = this._serializeRegister(cssResources, 'css');
6908
+ var loadRegister = this._serializeRegister(loadResources, 'load');
6909
+ var version = this._serializeVersion();
6910
+ var config = this._serializeConfig();
6911
+ var heading = `
6912
+ ${version}
6913
+ ${config}
6914
+ include.pauseStack();
6915
+ ${jsRegister}
6916
+ ${cssRegister}
6917
+ ${loadRegister}
6918
+ `;
6919
+ return heading;
6920
+ }
6921
+ _serializeVersion() {
6922
+ var v = this.solution.opts.version;
6923
+ if (!v)
6924
+ return '';
6925
+ return `include.cfg('version', '${v}');`;
6926
+ }
6927
+ _serializeConfig() {
6928
+ var opts = Include_1.Include.getConfig();
6929
+ var json = JSON.stringify(opts);
6930
+ if (json === '{}')
6931
+ return '';
6932
+ return `include.cfg(${json});`;
6933
+ }
6934
+ _serializeRegister(resources, type) {
6935
+ var paths = resources
6936
+ .filter(x => x.type === type)
6937
+ .map(x => {
6938
+ return {
6939
+ type: type,
6940
+ url: x.toTargetUrl(this.solution)
6839
6941
  };
6840
- if (json.outer.length === 0) {
6841
- delete json.outer;
6842
- }
6843
- if (json.scoped.length === 0) {
6844
- delete json.scoped;
6845
- }
6846
- return json;
6942
+ });
6943
+ if (paths.length === 0) {
6944
+ return '';
6945
+ }
6946
+ var json = JSON.stringify({
6947
+ [type]: paths
6948
+ });
6949
+ return `
6950
+ include.register(${json});
6951
+ `;
6952
+ }
6953
+ }
6954
+ exports.IncludeJsBuilder = IncludeJsBuilder;
6955
+ ;
6956
+ //# sourceMappingURL=IncludeJsBuilder.js.map
6957
+ //# sourceMappingURL=IncludeJsBuilder.ts.map;
6958
+
6959
+ function __isObj(x) {
6960
+ return x != null && typeof x === 'object' && x.constructor === Object;
6961
+ }
6962
+ if (_src_handlers_script_include_js_IncludeJsBuilder === module.exports) {
6963
+ // do nothing if
6964
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsBuilder) && __isObj(module.exports)) {
6965
+ Object.assign(_src_handlers_script_include_js_IncludeJsBuilder, module.exports);
6966
+ } else {
6967
+ _src_handlers_script_include_js_IncludeJsBuilder = module.exports;
6968
+ }
6969
+
6970
+ ;
6971
+ }());
6972
+
6973
+ // end:source ./ModuleSimplified.js
6974
+
6975
+
6976
+ // source ./ModuleSimplified.js
6977
+ var _src_handlers_script_include_js_IncludeJsRewriter;
6978
+ (function () {
6979
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6980
+ var define = null;
6981
+ var exports = _src_handlers_script_include_js_IncludeJsRewriter != null ? _src_handlers_script_include_js_IncludeJsRewriter : {};
6982
+ var module = { exports: exports };
6983
+
6984
+ "use strict";
6985
+ Object.defineProperty(exports, "__esModule", { value: true });
6986
+ exports.IncludeJsRewriter = void 0;
6987
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6988
+ class IncludeJsRewriter extends BaseRewriter_1.BaseRewriter {
6989
+ rewritePartial(content, ownerResource) {
6990
+ }
6991
+ rewriteResource(resource) {
6992
+ if (resource.getModule() === 'global' && resource && resource.meta && resource.meta.includejs && resource.meta.includejs.hasIncludes) {
6993
+ resource.asModules = ['includejs'];
6847
6994
  }
6848
- return toJSON(this);
6995
+ }
6996
+ accepts(type) {
6997
+ return type === 'js';
6849
6998
  }
6850
6999
  }
6851
- exports.ModuleFile = ModuleFile;
6852
- //# sourceMappingURL=ModuleFile.js.map
6853
- //# sourceMappingURL=ModuleFile.ts.map;
7000
+ exports.IncludeJsRewriter = IncludeJsRewriter;
7001
+ ;
7002
+ //# sourceMappingURL=IncludeJsRewriter.js.map
7003
+ //# sourceMappingURL=IncludeJsRewriter.ts.map;
6854
7004
 
6855
7005
  function __isObj(x) {
6856
7006
  return x != null && typeof x === 'object' && x.constructor === Object;
6857
7007
  }
6858
- if (_src_handlers_script_import_js_ModuleFile === module.exports) {
7008
+ if (_src_handlers_script_include_js_IncludeJsRewriter === module.exports) {
6859
7009
  // do nothing if
6860
- } else if (__isObj(_src_handlers_script_import_js_ModuleFile) && __isObj(module.exports)) {
6861
- Object.assign(_src_handlers_script_import_js_ModuleFile, module.exports);
7010
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsRewriter) && __isObj(module.exports)) {
7011
+ Object.assign(_src_handlers_script_include_js_IncludeJsRewriter, module.exports);
6862
7012
  } else {
6863
- _src_handlers_script_import_js_ModuleFile = module.exports;
7013
+ _src_handlers_script_include_js_IncludeJsRewriter = module.exports;
6864
7014
  }
6865
7015
 
6866
7016
  ;
@@ -6870,208 +7020,71 @@ exports.ModuleFile = ModuleFile;
6870
7020
 
6871
7021
 
6872
7022
  // source ./ModuleSimplified.js
6873
- var _src_handlers_script_import_js_Parser;
7023
+ var _src_handlers_script_include_js_IncludeJsHandler;
6874
7024
  (function () {
6875
7025
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6876
7026
  var define = null;
6877
- var exports = _src_handlers_script_import_js_Parser != null ? _src_handlers_script_import_js_Parser : {};
7027
+ var exports = _src_handlers_script_include_js_IncludeJsHandler != null ? _src_handlers_script_include_js_IncludeJsHandler : {};
6878
7028
  var module = { exports: exports };
6879
7029
 
6880
7030
  "use strict";
6881
7031
  Object.defineProperty(exports, "__esModule", { value: true });
6882
- exports.Parser = void 0;
6883
- const ModuleFile_1 = _src_handlers_script_import_js_ModuleFile;
6884
- const ResourceInfo_1 = _src_class_ResourceInfo;
6885
- let Rgx = {
6886
- Imports: {
6887
- full: {
6888
- rgx: /^[ \t]*import\s*(\*\s+as\s+\w+\s+from\s+)?['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6889
- map(match) {
6890
- let $import = new ResourceInfo_1.ImportNode();
6891
- $import.position = match.index;
6892
- $import.length = match[0].length;
6893
- $import.type = 'full';
6894
- $import.path = match.groups.path;
6895
- return $import;
6896
- }
6897
- },
6898
- refs: {
6899
- rgx: /^[ \t]*import\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6900
- map(match) {
6901
- let $import = new ResourceInfo_1.ImportNode();
6902
- $import.position = match.index;
6903
- $import.length = match[0].length;
6904
- $import.type = 'refs';
6905
- $import.path = match[2];
6906
- $import.refs = match[1].split(',').map(x => x.trim());
6907
- return $import;
6908
- }
6909
- },
6910
- defaults: {
6911
- rgx: /^[ \t]*import\s+(?<def>\w+)\s+from\s*['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6912
- map(match) {
6913
- let $import = new ResourceInfo_1.ImportNode();
6914
- $import.position = match.index;
6915
- $import.length = match[0].length;
6916
- $import.type = 'full';
6917
- $import.path = match.groups.path;
6918
- return $import;
6919
- }
6920
- },
6921
- exportAll: {
6922
- rgx: /^[ \t]*export\s+\*\s+from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6923
- map(match) {
6924
- let $import = new ResourceInfo_1.ImportNode();
6925
- $import.position = match.index;
6926
- $import.length = match[0].length;
6927
- $import.type = 'exportAll';
6928
- $import.path = match[1];
6929
- $import.exportAll = true;
6930
- return $import;
6931
- }
6932
- },
6933
- exportRefs: {
6934
- rgx: /^[ \t]*export\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6935
- map(match) {
6936
- let $import = new ResourceInfo_1.ImportNode();
6937
- $import.position = match.index;
6938
- $import.length = match[0].length;
6939
- $import.type = 'exportRefs';
6940
- $import.path = match[2];
6941
- $import.refs = match[1].split(',').map(x => x.trim());
6942
- $import.exportRefs = true;
6943
- return $import;
6944
- }
6945
- }
6946
- },
6947
- Exports: {
6948
- ref: {
6949
- rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[^\w\d_$;])/gm,
6950
- map(match) {
6951
- let $export = new ResourceInfo_1.ExportNode();
6952
- $export.position = match.index;
6953
- $export.length = match[0].length;
6954
- $export.type = 'ref';
6955
- $export.ref = match[2];
6956
- return $export;
6957
- }
6958
- },
6959
- named: {
6960
- rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[;])/gm,
6961
- map(match) {
6962
- let $export = new ResourceInfo_1.ExportNode();
6963
- $export.position = match.index;
6964
- $export.length = match[0].length;
6965
- $export.type = 'named';
6966
- $export.ref = match[2];
6967
- return $export;
6968
- }
6969
- },
6970
- scoped: {
6971
- rgx: /^[ \t]*export\s*\{([^}]+)}\s*;?(?!\s*from)/gm,
6972
- map(match) {
6973
- let refs = match[1].split(',').map(x => x.trim());
6974
- let $export = new ResourceInfo_1.ExportNode();
6975
- $export.position = match.index;
6976
- $export.length = match[0].length;
6977
- $export.type = 'scoped';
6978
- $export.ref = refs[0];
6979
- let other = refs.slice(1).map(ref => {
6980
- let $export = new ResourceInfo_1.ExportNode();
6981
- $export.position = match.index;
6982
- $export.length = 0;
6983
- $export.type = 'scoped';
6984
- $export.ref = ref;
6985
- return $export;
6986
- });
6987
- return [$export, ...other];
6988
- }
6989
- },
6990
- function: {
6991
- rgx: /^[ \t]*export\s*function\s+([\w\d_$]+)/gm,
6992
- map(match) {
6993
- let $export = new ResourceInfo_1.ExportNode();
6994
- $export.position = match.index;
6995
- $export.length = match[0].length;
6996
- $export.type = 'function';
6997
- $export.ref = match[1];
6998
- return $export;
6999
- }
7000
- }
7032
+ exports.IncludeJsHandler = void 0;
7033
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
7034
+ const Include_1 = _src_class_Include;
7035
+ const IncludeJsParser_1 = _src_handlers_script_include_js_IncludeJsParser;
7036
+ const IncludeJsBuilder_1 = _src_handlers_script_include_js_IncludeJsBuilder;
7037
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
7038
+ const IncludeJsRewriter_1 = _src_handlers_script_include_js_IncludeJsRewriter;
7039
+ class IncludeJsHandler extends BaseHandler_1.BaseHandler {
7040
+ constructor(solution) {
7041
+ super(solution);
7042
+ // if (this.solution.opts.package.module === 'includejs') {
7043
+ // this.registerMappings_();
7044
+ // }
7001
7045
  }
7002
- };
7003
- class Parser {
7004
- static supports(content) {
7005
- for (let type in Rgx) {
7006
- for (let key in Rgx[type]) {
7007
- let rgx = Rgx[type][key].rgx;
7008
- rgx.lastIndex = 0;
7009
- if (rgx.test(content)) {
7010
- return true;
7011
- }
7012
- }
7046
+ accepts(resource) {
7047
+ if (resource.type !== 'js') {
7048
+ return false;
7013
7049
  }
7014
- return false;
7050
+ var module = resource.getModule();
7051
+ if (module == null || module === 'root')
7052
+ module = this.solution.opts.package.module;
7053
+ return module === 'includejs';
7015
7054
  }
7016
- static parse(content, file) {
7017
- let module = new ModuleFile_1.ModuleFile(content, file);
7018
- if (Parser.supports(content) === false) {
7019
- return module;
7020
- }
7021
- for (let key in Rgx.Imports) {
7022
- let x = Rgx.Imports[key];
7023
- x.rgx.lastIndex = 0;
7024
- for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
7025
- let result = x.map(match, content);
7026
- if (Array.isArray(result)) {
7027
- module.imports.push(...result);
7028
- }
7029
- else {
7030
- module.imports.push(result);
7031
- }
7032
- }
7033
- }
7034
- for (let key in Rgx.Exports) {
7035
- let x = Rgx.Exports[key];
7036
- x.rgx.lastIndex = 0;
7037
- for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
7038
- let result = x.map(match, content);
7039
- if (Array.isArray(result)) {
7040
- module.exports.push(...result);
7041
- }
7042
- else {
7043
- module.exports.push(result);
7044
- }
7045
- }
7046
- }
7047
- module.imports.forEach(m => m.parent = module);
7048
- module.imports.filter(x => x.type === 'exportRefs').forEach(imp => {
7049
- imp.refs.forEach(ref => {
7050
- let exp = new ResourceInfo_1.ExportNode();
7051
- exp.position = 0;
7052
- exp.length = 0;
7053
- exp.ref = ref;
7054
- module.exports.push(exp);
7055
- });
7056
- });
7057
- module.imports.sort((a, b) => a.position < b.position ? -1 : 1);
7058
- module.exports.sort((a, b) => a.position < b.position ? -1 : 1);
7059
- return module;
7055
+ rewriteRoot(root, dependencies) {
7056
+ dependencies.forEach(x => x.embed = true);
7057
+ var body = dependencies
7058
+ .map(x => x.content)
7059
+ .concat([root.content])
7060
+ .join('\n');
7061
+ body = Templates_1.Templates.RootModule.replace('%BUNDLE%', () => body);
7062
+ root.content = body;
7063
+ }
7064
+ resolvePath(includeData, parent) {
7065
+ return Include_1.Include
7066
+ .PathResolver
7067
+ .resolveBasic(includeData.url, includeData.type, parent);
7060
7068
  }
7061
7069
  }
7062
- exports.Parser = Parser;
7063
- //# sourceMappingURL=Parser.js.map
7064
- //# sourceMappingURL=Parser.ts.map;
7070
+ exports.IncludeJsHandler = IncludeJsHandler;
7071
+ IncludeJsHandler.Parser = IncludeJsParser_1.IncludeJsParser;
7072
+ IncludeJsHandler.Rewriter = IncludeJsRewriter_1.IncludeJsRewriter;
7073
+ IncludeJsHandler.Builder = IncludeJsBuilder_1.IncludeJsBuilder;
7074
+ IncludeJsHandler.PathResolver = null;
7075
+ ;
7076
+ //# sourceMappingURL=IncludeJsHandler.js.map
7077
+ //# sourceMappingURL=IncludeJsHandler.ts.map;
7065
7078
 
7066
7079
  function __isObj(x) {
7067
7080
  return x != null && typeof x === 'object' && x.constructor === Object;
7068
7081
  }
7069
- if (_src_handlers_script_import_js_Parser === module.exports) {
7082
+ if (_src_handlers_script_include_js_IncludeJsHandler === module.exports) {
7070
7083
  // do nothing if
7071
- } else if (__isObj(_src_handlers_script_import_js_Parser) && __isObj(module.exports)) {
7072
- Object.assign(_src_handlers_script_import_js_Parser, module.exports);
7084
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsHandler) && __isObj(module.exports)) {
7085
+ Object.assign(_src_handlers_script_include_js_IncludeJsHandler, module.exports);
7073
7086
  } else {
7074
- _src_handlers_script_import_js_Parser = module.exports;
7087
+ _src_handlers_script_include_js_IncludeJsHandler = module.exports;
7075
7088
  }
7076
7089
 
7077
7090
  ;