requirejs-esm 2.0.1 → 2.2.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "requirejs-esm",
3
- "version": "2.0.1",
3
+ "version": "2.2.1",
4
4
  "description": "A RequireJS plugin converting JavaScript modules from ESM to AMD.",
5
5
  "author": "Ferdinand Prantl <prantlf@gmail.com>",
6
6
  "license": "MIT",
@@ -22,12 +22,15 @@
22
22
  "node": ">=14"
23
23
  },
24
24
  "main": "dist/api.js",
25
+ "module": "src/api.js",
26
+ "types": "src/api.d.ts",
25
27
  "bin": {
26
28
  "esm2requirejs": "bin/esm2requirejs.js"
27
29
  },
28
30
  "files": [
29
31
  "bin",
30
- "dist"
32
+ "dist",
33
+ "src"
31
34
  ],
32
35
  "scripts": {
33
36
  "prepare": "npm run build && npm run demo",
@@ -39,10 +42,11 @@
39
42
  "demo:local": "npm run optimize:local && npm run minify:local",
40
43
  "optimize:local": "r.js -o demo-local/build.config.js",
41
44
  "minify:local": "terser -cm --ecma 2018 --comments false --source-map content=demo-local/main-built.js.map --source-map includeSources --source-map url=main-built.min.js.map -o demo-local/main-built.min.js demo-local/main-built.js",
42
- "lint": "eslint -c .eslintrc.browser.yml src && eslint -c .eslintrc.node.yml *.js perf/*.js bin 'test/*.js'",
45
+ "lint": "eslint -c .eslintrc.browser.yml src && eslint -c .eslintrc.node.yml perf/*.js bin 'test/*.js'",
43
46
  "check": "tehanu test/*.js",
44
47
  "cover": "c8 node test && c8 --no-clean ./bin/esm2requirejs.js && c8 --no-clean ./bin/esm2requirejs.js test/input/esm-import-all.js && c8 --no-clean ./bin/esm2requirejs.js dummy || c8 report -r text -r lcov | grep -Ev '(\\.\\.\\.)|(index.mjs)|(source-map.js)|(base64-vlq.js)|(base64.js)|(binary-search.js)|(mapping-list.js)|(read-wasm-browser.js)|(url-browser.js)|(wasm.js)|(regexes.js)|(public-api.js)|(All files)' && c8 check-coverage",
45
- "test": "npm run lint && npm run cover"
48
+ "test": "npm run lint && npm run cover",
49
+ "start": "python3 -m http.server"
46
50
  },
47
51
  "tehanu": {
48
52
  "autostart": false
@@ -78,33 +82,31 @@
78
82
  "@semantic-release/git"
79
83
  ]
80
84
  },
81
- "devDependencies": {
85
+ "dependencies": {
82
86
  "@prantlf/convert-source-map": "^2.0.0",
83
- "@prantlf/requirejs": "^2.5.0",
84
- "@rollup/plugin-commonjs": "^21.0.3",
85
- "@rollup/plugin-json": "^4.1.0",
86
- "@rollup/plugin-node-resolve": "^13.1.3",
87
- "@semantic-release/changelog": "^6.0.1",
88
- "@semantic-release/git": "^10.0.1",
89
- "astring": "^1.8.1",
90
- "c8": "^7.11.0",
87
+ "astring": "^1.8.3",
91
88
  "charcodes": "^0.2.0",
92
- "connect": "^3.7.0",
93
- "connect-block-favicon": "^1.0.4",
94
- "escodegen": "^2.0.0",
95
- "eslint": "^8.12.0",
96
- "lit-html": "^1",
89
+ "commander": "^9.3.0",
97
90
  "meriyah": "^4.2.1",
98
- "morgan": "^1.10.0",
99
91
  "punycode": "^2.1.1",
100
- "rollup": "^2.70.1",
101
- "serve-index": "^1.9.1",
102
- "serve-static": "^1.15.0",
103
92
  "source-map": "^0.8.0-beta.0",
104
- "tehanu": "^0.2.2",
105
- "tehanu-repo-coco": "^0.0.2",
106
- "tehanu-teru": "^0.2.2",
107
- "terser": "^5.12.1"
93
+ "tiny-glob": "^0.2.9"
94
+ },
95
+ "devDependencies": {
96
+ "@prantlf/requirejs": "^3.0.0",
97
+ "@rollup/plugin-commonjs": "^22.0.1",
98
+ "@rollup/plugin-json": "^4.1.0",
99
+ "@rollup/plugin-node-resolve": "^13.3.0",
100
+ "@semantic-release/changelog": "^6.0.1",
101
+ "@semantic-release/git": "^10.0.1",
102
+ "c8": "^7.11.3",
103
+ "eslint": "^8.19.0",
104
+ "lit-html": "^1",
105
+ "rollup": "^2.76.0",
106
+ "tehanu": "^1.0.1",
107
+ "tehanu-repo-coco": "^1.0.0",
108
+ "tehanu-teru": "^1.0.0",
109
+ "terser": "^5.14.1"
108
110
  },
109
111
  "keywords": [
110
112
  "requirejs-plugin",
@@ -113,12 +115,5 @@
113
115
  "amd",
114
116
  "esm",
115
117
  "es6"
116
- ],
117
- "dependencies": {
118
- "commander": "^9.1.0",
119
- "cors": "^2.8.5",
120
- "mime": "^3.0.0",
121
- "polka": "^0.5.2",
122
- "tiny-glob": "^0.2.9"
123
- }
118
+ ]
124
119
  }
package/src/api.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ type NeedsResolve = (sourcePath: string, currentFile: string) => boolean
2
+
3
+ interface ResolveOptions {
4
+ pluginName?: string
5
+ needsResolve?: NeedsResolve
6
+ }
7
+
8
+ declare function resolvePath(sourcePath: string, currentFile: string, options?: ResolveOptions): string
9
+
10
+ type ResolvePath = ((sourcePath: string, currentFile: string, options?: ResolveOptions) => string) | false
11
+
12
+ declare function transform(contents: string, path: string, options?: {
13
+ pluginName?: string /*= 'esm'' */, resolvePath?: ResolvePath,
14
+ sourceMap?: boolean /*= true */ }): string
15
+
16
+ declare function transformAst(ast: object): { amd?: true, updated?: true }
17
+
18
+ declare function detectDefinesOrRequires(ast: object): {
19
+ namespace?: object
20
+ func: object
21
+ name?: object
22
+ deps?: object[]
23
+ factory?: object
24
+ output?: object
25
+ body?: object
26
+ }[]
27
+
28
+ declare function detectImportsAndExports(ast: object): {
29
+ imports: {
30
+ node: object
31
+ source: string
32
+ local?: string
33
+ specifiers?: { imported: string, local: string }[]
34
+ export?: true
35
+ }[]
36
+ exports: {
37
+ node: object,
38
+ default?: true
39
+ import?: true
40
+ }[]
41
+ }
package/src/api.js ADDED
@@ -0,0 +1,3 @@
1
+ export { resolvePath } from './resolve-path'
2
+ export { default as transform } from './transform'
3
+ export { transformAst, detectDefinesOrRequires, detectImportsAndExports } from './transformer'
@@ -0,0 +1,35 @@
1
+ /* global require */
2
+
3
+ let fetchText
4
+
5
+ // Initialise the fetchText variable with a function to download
6
+ // from a URL or to read from the file system.
7
+ /* istanbul ignore if */
8
+ if (typeof window !== 'undefined' && window.navigator && window.document) {
9
+ fetchText = (url, callback) => {
10
+ const xhr = new XMLHttpRequest()
11
+ xhr.open('GET', url, true)
12
+ xhr.onreadystatechange = () => {
13
+ if (xhr.readyState === 4) {
14
+ if (xhr.status === 200) {
15
+ callback(null, xhr.responseText)
16
+ } else {
17
+ callback(new Error(xhr.statusText))
18
+ }
19
+ }
20
+ }
21
+ xhr.send(null)
22
+ }
23
+ } else {
24
+ const { readFileSync } = require.nodeRequire ? require.nodeRequire('fs') : require('fs')
25
+ fetchText = (path, callback) => {
26
+ // Asynchronous reading is not possible during the build in the optimizer.
27
+ try {
28
+ callback(null, readFileSync(path, 'utf8'))
29
+ } catch (error) {
30
+ callback(error)
31
+ }
32
+ }
33
+ }
34
+
35
+ export default fetchText
package/src/plugin.js ADDED
@@ -0,0 +1,147 @@
1
+ /* global module */
2
+
3
+ import fetchText from './fetch-text'
4
+ import writeText from './write-text'
5
+ import { childFile } from './resolve-path'
6
+ import { setSkipModules, skipModule } from './skip-module'
7
+ import transformSource from './transform'
8
+
9
+ const {
10
+ // Allow using a different plugin alias than `esm` in the source code.
11
+ pluginName,
12
+ // Assume that the original sources are JavaScript files by default.
13
+ fileExtension = '.js',
14
+ // Flags to enforce or suppress the transpilation of not yet defined modules.
15
+ mixedAmdAndEsm,
16
+ onlyAmd,
17
+ // List of module names not to check and transform.
18
+ skipModules = [],
19
+ // Method to update paths of module dependencies, to prefix JavaScript module
20
+ // name with `esm!`, above all.
21
+ resolvePath,
22
+ // ecmaVersion,
23
+ // Boolean or object with booleans { inline, content }.
24
+ sourceMap,
25
+ // Enable console logging.
26
+ verbose,
27
+ // Directory to save a copy of the transformed modules.
28
+ debugDir
29
+ } = typeof module !== 'undefined' && module.config && module.config() || {}
30
+
31
+ const buildMap = {}
32
+
33
+ setSkipModules(skipModules)
34
+
35
+ //>>excludeEnd('excludeEsm')
36
+ export default {
37
+ load(name, req, onload, reqConfig) {
38
+ //>>excludeStart('excludeEsm', pragmas.excludeEsm)
39
+ const { isBuild } = reqConfig
40
+ // if (!bundledModules) {
41
+ // bundledModules = new Set()
42
+ // const { bundles } = reqConfig
43
+ // if (bundles) {
44
+ // verbose && console.log('esm: initialising bundles', name)
45
+ // for (const bundle in bundles) {
46
+ // for (const module of bundles[bundle]) {
47
+ // bundledModules.add(module)
48
+ // }
49
+ // }
50
+ // }
51
+ // }
52
+
53
+ // Paths relative to the current directory include the file extension.
54
+ // Otherwise the file extension must not be used for JavaScript modules.
55
+ // The file name should include the orioginal extension in the source maps.
56
+ const file = name.endsWith(fileExtension) ? name : name + fileExtension
57
+ // Compilation and bundling of module sub-trees can be skipped, if those
58
+ // are mapped to the pseudo-path `empty:`, meaning that those modules
59
+ // are external and will be loaded during the runtime.
60
+ const url = req.toUrl(file)
61
+ if (url.startsWith('empty:')) {
62
+ verbose && console.log('esm: skipping', name, 'mapped to', url)
63
+ return onload()
64
+ }
65
+
66
+ verbose && console.log('esm: loading', name)
67
+ // If the module has been already defined from a module bundle, it was
68
+ // already transpiled, when the output bundle was written. No need to
69
+ // re-transpile it. This can happen only during the runtime.
70
+ //
71
+ // The re-transpilation is however necessary, if a testing page or a unit
72
+ // test loads source ESM modules with extensions, which are going to be
73
+ // consumed by a bundled module. Then the bundled module has to prefix
74
+ // each of its dependencies with `esm!` to ensure their transpilation.
75
+ // This mixed mode can to be enabled by the flag `mixedAmdAndEsm`, if needed.
76
+ //
77
+ // If the whole application is transpiled, there is no need to transpile
78
+ // ESM modules or prefix dependencies of AMD modules. Even not yet defined
79
+ // modules can be loaded just by `require` to get better performance.
80
+ if (!mixedAmdAndEsm && !isBuild && req.specified(name) ||
81
+ /*bundledModules.has(name) ||*/ onlyAmd || skipModule(name) ||
82
+ // If the module was bundled, it had to be already transpiled.
83
+ !isBuild && childFile(url) !== childFile(file)) {
84
+ verbose && console.log('esm: delegating', name)
85
+ //>>excludeEnd('excludeEsm')
86
+ return req([name], onload, onload.error)
87
+ //>>excludeStart('excludeEsm', pragmas.excludeEsm)
88
+ }
89
+
90
+ // Fetch the text of the source module by AJAX and transpile it.
91
+ verbose && console.log('esm: fetching', name, 'mapped to', url)
92
+ fetchText(url, async (error, text) => {
93
+ if (error) {
94
+ verbose && console.log('esm: missing', name)
95
+ return onload.error(error)
96
+ }
97
+
98
+ let code, updated
99
+ try {
100
+ verbose && console.log('esm: transforming', name);
101
+ ({ code, updated } = transformSource(text, file, {
102
+ pluginName,
103
+ resolvePath,
104
+ /*ecmaVersion,*/
105
+ // Always produce the source maps when transpiling in the browser, otherwise
106
+ // the debugging would me impossible. When building and bundling, check if
107
+ // the source maps were enabled for the output.
108
+ sourceMap: sourceMap || !isBuild
109
+ }))
110
+ if (!updated) {
111
+ verbose && console.log('esm: retaining', name)
112
+ // return req([name], onload, onload.error)
113
+ } else if (isBuild && debugDir) {
114
+ writeText(`${debugDir}/${file}`, code)
115
+ }
116
+ } catch (error) {
117
+ // RequireJS did not always log this error.
118
+ console.error(`Transforming "${name}" (resolved to "${url}") failed:`)
119
+ console.error(error)
120
+ return onload.error(error)
121
+ }
122
+
123
+ // Remember the transpiled content for the writing phase during the build.
124
+ if (isBuild) {
125
+ buildMap[name] = code
126
+ }
127
+
128
+ verbose && console.log('esm: returning', name)
129
+ onload.fromText(code)
130
+ })
131
+ },
132
+
133
+ write(pluginName, moduleName, write) {
134
+ const code = buildMap[moduleName]
135
+ if (code) {
136
+ // Add the transpiled module under the original name. Earlier modules
137
+ // refer it with that name, before the module was converted to ESM.
138
+ write.asModule(moduleName, code)
139
+ // Add a stub of the module with the name prefixed by `esm!`. Modules
140
+ // compiled with esm refer it with that name and this stub will simplify
141
+ // the module loading by skipping the plugin evaluation.
142
+ write.asModule(`${pluginName}!${moduleName}`,
143
+ '\ndefine([\'' + moduleName + '\'], res => res);\n')
144
+ }
145
+ //>>excludeEnd('excludeEsm')
146
+ }
147
+ }
@@ -0,0 +1,80 @@
1
+ // Returns the child file name by cutting the directoris before the last slash,
2
+ // including the slash. If there is no slash in the path - the path is just
3
+ // a file name, it will return the file name. If the path includes a URL
4
+ // query starting with the question mark, it will cut it away including the
5
+ // question mark.
6
+ export function childFile (path) {
7
+ const lastSlash = path.lastIndexOf('/')
8
+ if (lastSlash > 0) {
9
+ path = path.substring(lastSlash + 1)
10
+ }
11
+ const questionMark = path.lastIndexOf('?')
12
+ return questionMark > 0 ? path.substring(0, questionMark) : path
13
+ }
14
+
15
+ // Returns the parent directory by cutting the file name after the last slash,
16
+ // leaving the slash in the result. If there is no slash in the path - the path
17
+ // is just a file name, it will return `undefined`.
18
+ function parentDir (path) {
19
+ const lastSlash = path.lastIndexOf('/')
20
+ return lastSlash > 0 ? path.substring(0, lastSlash + 1) : undefined
21
+ }
22
+
23
+ // Trims the leading "./" off the path.
24
+ function shortenPath(path) {
25
+ while (path.charAt(0) === '.' && path.charAt(1) === '/') {
26
+ path = path.substring(2)
27
+ }
28
+ return path
29
+ }
30
+
31
+ // Checks if the path starts with "../".
32
+ function pointsToParent(path) {
33
+ return path.charAt(0) === '.' && path.charAt(1) === '.' && path.charAt(2) === '/'
34
+ }
35
+
36
+ // Joins two paths together and avoids leaving "/./" or "/../" in the middle.
37
+ function joinPath (first, second) {
38
+ // If the second part starts with "./", it can be safely removed.
39
+ second = shortenPath(second)
40
+ // The parent path can be undefined, if the file is located in the current directory.
41
+ if (first !== undefined) {
42
+ // As long as "../" can be removed from the second path, shorten the first one.
43
+ while (pointsToParent(second)) {
44
+ // Remove the leading "../" and trim futher all leading "./".
45
+ second = shortenPath(second.substring(3))
46
+ // Cut the last directory from the first path.
47
+ first = parentDir(first)
48
+ // If the last part of the first path was removed and there is no parent
49
+ // directory to go further, return the rest of the second path.
50
+ if (first === undefined) {
51
+ return second
52
+ }
53
+ }
54
+ // Return what remains from the first path concatenated with the second one.
55
+ second = first + second
56
+ }
57
+ return second
58
+ }
59
+
60
+ // Ensures that every JavaScript dependency will be prefixed by `esm!`.
61
+ // Relative paths will be converted to be relative to the parent module.
62
+ export function resolvePath (sourcePath, currentFile, { pluginName, needsResolve } = {}) {
63
+ // Ignore paths with other plugins applied and the three built-in
64
+ // pseudo-modules of RequireJS.
65
+ if (sourcePath.includes('!') || sourcePath === 'require' ||
66
+ sourcePath === 'module' || sourcePath === 'exports') return
67
+
68
+ // If `sourcePath` is relative to `currentFile` - starts with ./ or ../ -
69
+ // prepend the parent directory of `currentFile` to it. This was needed
70
+ // for modules located outside the source root (`baseUrl`), which were
71
+ // mapped there using the `paths` of `map` configuration properties.
72
+ if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
73
+ sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
74
+ !(needsResolve && needsResolve(sourcePath, currentFile))) {
75
+ sourcePath = joinPath(parentDir(currentFile), sourcePath)
76
+ if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3)
77
+ }
78
+
79
+ return pluginName ? `${pluginName}!${sourcePath}` : sourcePath
80
+ }
@@ -0,0 +1,18 @@
1
+ let skipModules = []
2
+
3
+ export function setSkipModules(names) {
4
+ skipModules = names
5
+ }
6
+
7
+ // Checks if a module name is included in the list of modules to skip
8
+ // the transformation.
9
+ export function skipModule(name) {
10
+ for (const skipModule of skipModules) {
11
+ // Recognise an asterisk at the beginning
12
+ if (skipModule.startsWith('*')) {
13
+ if (name.indexOf(skipModule.substring(1)) >= 0) return true
14
+ }
15
+ // Accept a path prefix as well.
16
+ else if (name.startsWith(skipModule)) return true
17
+ }
18
+ }
@@ -0,0 +1,46 @@
1
+ import { resolvePath as originalResolvePath } from './resolve-path'
2
+ // import { parse } from 'acorn'
3
+ import { parseModule } from 'meriyah'
4
+ import { generate } from 'astring'
5
+ import { SourceMapGenerator } from 'source-map'
6
+ import convert from '@prantlf/convert-source-map'
7
+ import { transformAst } from './transformer'
8
+
9
+ export default function transform(text, file, {
10
+ // Allow using a different plugin alias than `esm` in the source code.
11
+ pluginName = 'esm',
12
+ // Method to update paths of module dependencies, to prefix JavaScript module
13
+ // name with `esm!`, above all.
14
+ resolvePath = originalResolvePath,
15
+ // ecmaVersion = 2020,
16
+ sourceMap
17
+ } = {}) {
18
+ // const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
19
+ let ast = parseModule(text, { next: true, loc: true })
20
+
21
+ const options = { sourceFileName: file, pluginName, resolvePath, originalResolvePath }
22
+ const { updated } = transformAst(ast, options)
23
+
24
+ let code, map
25
+ if (updated) {
26
+ if (sourceMap === true) {
27
+ sourceMap = { inline: true, content: true }
28
+ }
29
+ const mapGenerator = sourceMap ? new SourceMapGenerator({ file }) : undefined
30
+ code = generate(ast, { sourceMap: mapGenerator })
31
+ if (sourceMap) {
32
+ if (sourceMap.content) {
33
+ mapGenerator.setSourceContent(file, text)
34
+ }
35
+ if (sourceMap.inline) {
36
+ code += convert.fromObject(mapGenerator.toJSON()).toComment()
37
+ } else {
38
+ map = mapGenerator.toJSON()
39
+ }
40
+ }
41
+ } else {
42
+ code = text
43
+ }
44
+
45
+ return { code, map, updated }
46
+ }
@@ -0,0 +1,106 @@
1
+ import { replaceLiteral } from './converters'
2
+
3
+ // Detects if an expression calls define or require function.
4
+ // Returns information about an AMD module false, { deps } or [{ deps }, ...].
5
+ function detectDefineOrRequireCall(expr) {
6
+ if (expr.type !== 'CallExpression') return false
7
+
8
+ const args = expr.arguments
9
+ const { length } = args
10
+ if (length === 0) return false
11
+
12
+ const { callee } = expr
13
+ let namespace, func
14
+ // namespace.define(...)
15
+ if (callee.type === 'MemberExpression') {
16
+ const { object } = callee
17
+ if (object.type !== 'Identifier') return false
18
+ namespace = object
19
+ func = callee.property
20
+ } else {
21
+ func = callee
22
+ }
23
+ if (func.type !== 'Identifier') return false
24
+
25
+ // define('name', [deps], factory)
26
+ if (func.name === 'define') {
27
+ let index = 0
28
+ let arg = args[index]
29
+ let name, deps
30
+ if (arg.type === 'Literal') {
31
+ if (length <= ++index || typeof arg.value !== 'string') return false
32
+ name = arg
33
+ arg = args[index]
34
+ }
35
+ if (arg.type === 'ArrayExpression') {
36
+ deps = arg
37
+ if (length <= ++index) return false
38
+ arg = args[index]
39
+ }
40
+ if (arg.type === 'FunctionExpression' || arg.type === 'ArrowFunctionExpression') {
41
+ return { namespace, func, name, deps, factory: arg }
42
+ }
43
+ return arg.type === 'ObjectExpression' && { namespace, func, name, deps, output: arg }
44
+ }
45
+
46
+ // require([deps], success, error)
47
+ if (func.name === 'require') {
48
+ const deps = args[0]
49
+ if (deps.type === 'ArrayExpression' && length >= 2) {
50
+ const body = args[1]
51
+ if (body.type === 'FunctionExpression' || body.type === 'ArrowFunctionExpression') {
52
+ return { func, deps, body }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ // Detects if a program contains statements calling define or require function.
59
+ // Returns information about AMD modules false, { deps } or [{ deps }, ...].
60
+ function detectDefineOrRequire(stat) {
61
+ if (stat.type !== 'ExpressionStatement') return false
62
+ const { expression } = stat
63
+
64
+ // multiple define/require statements in one file
65
+ if (expression.type === 'SequenceExpression') {
66
+ return expression
67
+ .expressions
68
+ .map(detectDefineOrRequireCall)
69
+ .reduce((all, one) => one ? all.concat(one) : all, [])
70
+ }
71
+
72
+ return detectDefineOrRequireCall(expression)
73
+ }
74
+
75
+ // Detects if a program contains statements calling define or require function.
76
+ // Returns information about the AMD modules [{ deps }, ...] or [].
77
+ export function detectDefinesOrRequires(program) {
78
+ const { body } = program
79
+ return body
80
+ .map(detectDefineOrRequire)
81
+ .reduce((all, one) => one ? all.concat(one) : all, [])
82
+ }
83
+
84
+ // Updates dependency paths to be prefixed by `esm!` or otherwise updated.
85
+ export function updateAmdDeps(amd, options) {
86
+ const { deps } = amd
87
+ if (!deps) return
88
+
89
+ const { sourceFileName: parentName } = options
90
+ const { elements } = deps
91
+ if (!elements.length) return
92
+
93
+ const { resolvePath } = options
94
+ let updated
95
+ for (const element of elements) {
96
+ if (element.type === 'Literal') {
97
+ const moduleName = element.value
98
+ const newModuleName = resolvePath(moduleName, parentName, options)
99
+ if (newModuleName && newModuleName !== moduleName) {
100
+ replaceLiteral(element, newModuleName)
101
+ updated = true
102
+ }
103
+ }
104
+ }
105
+ return updated
106
+ }