MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / parseModule

Method parseModule

tools/mcpack.js:348–433  ·  view source on GitHub ↗
(module)

Source from the content-addressed store, hash-verified

346
347 listSpecifiers(path) @ "Tool_prototype_listSpecifiers"
348 parseModule(module) {
349 if (module.fileURL.endsWith(".json"))
350 return;
351 let path = this.urlToFilePath(module.fileURL);
352 let infos = this.listSpecifiers(path);
353 if (infos) {
354 module.async = infos.async;
355 module.default = infos.default;
356 for (let specifier of infos.from) {
357 try {
358 let from = specifier.from;
359 let fileURL = this.ESM_RESOLVE(from, module.fileURL);
360 if (fileURL.startsWith("embedded:") || fileURL.startsWith("moddable:")) {
361 if (this.importedBuiltinSpecifiers.indexOf(fileURL) < 0)
362 this.importedBuiltinSpecifiers.push(fileURL)
363 }
364 else {
365 let packageURL = this.LOOKUP_PACKAGE_SCOPE(fileURL);
366 if (packageURL == null)
367 this.throwPackageNotFoundError();
368 let packageJSON = this.READ_PACKAGE_JSON(packageURL);
369 if (packageJSON == null)
370 this.throwPackageNotFoundError();
371 let packageName = packageJSON.name;
372 if (from.startsWith('/') || from.startsWith('./') || from.startsWith('../')) {
373 if (fileURL.indexOf(packageURL) == 0)
374 from = packageName + "/" + fileURL.slice(packageURL.length + 1);
375 else
376 this.throwInvalidModuleSpecifierError();
377 }
378 let item = this.modules.get(fileURL);
379 if (item) {
380 if (!item.specifiers.find(it => it === from))
381 item.specifiers.push(from);
382 }
383 else {
384 item = { fileURL, packageURL, packageName, specifiers: [ from ] };
385 this.modules.set(fileURL, item);
386 this.queue.push(item);
387 }
388 }
389 }
390 catch(e) {
391 this.reportError(path, specifier.line, e.message);
392 }
393 }
394 for (let string of infos.global) {
395 let global = this.globals[string];
396 if (global) {
397 let include = global.include;
398 if (include) {
399 if (this.hasCreationMain) {
400 if (this.manifest.include.indexOf(include) < 0) {
401 this.report(`# mcpack include: ${include}`);
402 this.manifest.include.push(include);
403 }
404 }
405 else {

Callers 1

runMethod · 0.80

Calls 12

urlToFilePathMethod · 0.80
ESM_RESOLVEMethod · 0.80
LOOKUP_PACKAGE_SCOPEMethod · 0.80
READ_PACKAGE_JSONMethod · 0.80
findMethod · 0.80
reportMethod · 0.80
sliceMethod · 0.65
getMethod · 0.65
setMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected