Skip to content

Commit f437843

Browse files
authored
chore(commonjs): transpile dynamic helper to ES5 (#1082)
* chore(commonjs): transpile dynamic helper to ES5 * test: update snapshot
1 parent 1f0e2cd commit f437843

File tree

3 files changed

+528
-528
lines changed

3 files changed

+528
-528
lines changed

packages/commonjs/src/helpers.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,32 @@ export function commonjsRegister (path, loader) {
7474
}
7575
7676
export function commonjsRegisterOrShort (path, to) {
77-
const resolvedPath = commonjsResolveImpl(path, null, true);
77+
var resolvedPath = commonjsResolveImpl(path, null, true);
7878
if (resolvedPath !== null && DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
7979
DYNAMIC_REQUIRE_CACHE[path] = DYNAMIC_REQUIRE_CACHE[resolvedPath];
8080
} else {
8181
DYNAMIC_REQUIRE_SHORTS[path] = to;
8282
}
8383
}
8484
85-
const DYNAMIC_REQUIRE_LOADERS = Object.create(null);
86-
const DYNAMIC_REQUIRE_CACHE = Object.create(null);
87-
const DYNAMIC_REQUIRE_SHORTS = Object.create(null);
88-
const DEFAULT_PARENT_MODULE = {
85+
var DYNAMIC_REQUIRE_LOADERS = Object.create(null);
86+
var DYNAMIC_REQUIRE_CACHE = Object.create(null);
87+
var DYNAMIC_REQUIRE_SHORTS = Object.create(null);
88+
var DEFAULT_PARENT_MODULE = {
8989
id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []
9090
};
91-
const CHECKED_EXTENSIONS = ['', '.js', '.json'];
91+
var CHECKED_EXTENSIONS = ['', '.js', '.json'];
9292
9393
function normalize (path) {
9494
path = path.replace(/\\\\/g, '/');
95-
const parts = path.split('/');
96-
const slashed = parts[0] === '';
97-
for (let i = 1; i < parts.length; i++) {
95+
var parts = path.split('/');
96+
var slashed = parts[0] === '';
97+
for (var i = 1; i < parts.length; i++) {
9898
if (parts[i] === '.' || parts[i] === '') {
9999
parts.splice(i--, 1);
100100
}
101101
}
102-
for (let i = 1; i < parts.length; i++) {
102+
for (var i = 1; i < parts.length; i++) {
103103
if (parts[i] !== '..') continue;
104104
if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {
105105
parts.splice(--i, 2);
@@ -117,9 +117,9 @@ function normalize (path) {
117117
function join () {
118118
if (arguments.length === 0)
119119
return '.';
120-
let joined;
121-
for (let i = 0; i < arguments.length; ++i) {
122-
let arg = arguments[i];
120+
var joined;
121+
for (var i = 0; i < arguments.length; ++i) {
122+
var arg = arguments[i];
123123
if (arg.length > 0) {
124124
if (joined === undefined)
125125
joined = arg;
@@ -134,9 +134,9 @@ function join () {
134134
}
135135
136136
function isPossibleNodeModulesPath (modulePath) {
137-
let c0 = modulePath[0];
137+
var c0 = modulePath[0];
138138
if (c0 === '/' || c0 === '\\\\') return false;
139-
let c1 = modulePath[1], c2 = modulePath[2];
139+
var c1 = modulePath[1], c2 = modulePath[2];
140140
if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||
141141
(c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;
142142
if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))
@@ -148,9 +148,9 @@ function dirname (path) {
148148
if (path.length === 0)
149149
return '.';
150150
151-
let i = path.length - 1;
151+
var i = path.length - 1;
152152
while (i > 0) {
153-
const c = path.charCodeAt(i);
153+
var c = path.charCodeAt(i);
154154
if ((c === 47 || c === 92) && i !== path.length - 1)
155155
break;
156156
i--;
@@ -166,9 +166,9 @@ function dirname (path) {
166166
}
167167
168168
export function commonjsResolveImpl (path, originalModuleDir, testCache) {
169-
const shouldTryNodeModules = isPossibleNodeModulesPath(path);
169+
var shouldTryNodeModules = isPossibleNodeModulesPath(path);
170170
path = normalize(path);
171-
let relPath;
171+
var relPath;
172172
if (path[0] === '/') {
173173
originalModuleDir = '/';
174174
}
@@ -185,8 +185,8 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
185185
break; // Travelled too far up, avoid infinite loop
186186
}
187187
188-
for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
189-
const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
188+
for (var extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
189+
var resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
190190
if (DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
191191
return resolvedPath;
192192
}
@@ -198,34 +198,34 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
198198
}
199199
}
200200
if (!shouldTryNodeModules) break;
201-
const nextDir = normalize(originalModuleDir + '/..');
201+
var nextDir = normalize(originalModuleDir + '/..');
202202
if (nextDir === originalModuleDir) break;
203203
originalModuleDir = nextDir;
204204
}
205205
return null;
206206
}
207207
208208
export function commonjsResolve (path, originalModuleDir) {
209-
const resolvedPath = commonjsResolveImpl(path, originalModuleDir);
209+
var resolvedPath = commonjsResolveImpl(path, originalModuleDir);
210210
if (resolvedPath !== null) {
211211
return resolvedPath;
212212
}
213213
return require.resolve(path);
214214
}
215215
216216
export function commonjsRequire (path, originalModuleDir) {
217-
let resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
217+
var resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
218218
if (resolvedPath !== null) {
219-
let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
219+
var cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
220220
if (cachedModule) return cachedModule.exports;
221-
let shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
221+
var shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
222222
if (shortTo) {
223223
cachedModule = DYNAMIC_REQUIRE_CACHE[shortTo];
224224
if (cachedModule)
225225
return cachedModule.exports;
226226
resolvedPath = commonjsResolveImpl(shortTo, null, true);
227227
}
228-
const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
228+
var loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
229229
if (loader) {
230230
DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {
231231
id: resolvedPath,

0 commit comments

Comments
 (0)