Skip to content

Commit 15343b0

Browse files
committed
Keep using indexOf in sandbox for now
1 parent a960e3c commit 15343b0

File tree

10 files changed

+33
-33
lines changed

10 files changed

+33
-33
lines changed

packages/app/src/sandbox/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function getDependencies(parsedPackage, templateDefinition, configurations) {
254254
Object.keys(devDependencies).forEach(dep => {
255255
const usedDep = DEPENDENCY_ALIASES[dep] || dep;
256256

257-
if (foundWhitelistedDevDependencies.includes(usedDep)) {
257+
if (foundWhitelistedDevDependencies.indexOf(usedDep) > -1) {
258258
if (
259259
usedDep === '@vue/babel-preset-app' &&
260260
devDependencies[dep].startsWith('^3')

packages/app/src/sandbox/eval/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export default class Manager {
604604
);
605605
const shimmedPath = coreLibraries[aliasedPath] || aliasedPath;
606606

607-
if (NODE_LIBS.includes(shimmedPath)) {
607+
if (NODE_LIBS.indexOf(shimmedPath) > -1) {
608608
this.cachedPaths[dirredPath][path] = shimmedPath;
609609
promiseResolve(getShimmedModuleFromPath(currentPath, path));
610610
return;
@@ -708,7 +708,7 @@ export default class Manager {
708708
);
709709
const shimmedPath = coreLibraries[aliasedPath] || aliasedPath;
710710

711-
if (NODE_LIBS.includes(shimmedPath)) {
711+
if (NODE_LIBS.indexOf(shimmedPath) > -1) {
712712
this.cachedPaths[dirredPath][path] = shimmedPath;
713713
return getShimmedModuleFromPath(currentPath, path);
714714
}

packages/app/src/sandbox/eval/tests/jest-lite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let jsdomPromise = null;
6060
const getJSDOM = () => {
6161
let jsdomPath = '/static/js/jsdom-4.0.0.min.js';
6262
if (
63-
navigator.userAgent.includes('jsdom') &&
63+
navigator.userAgent.indexOf('jsdom') !== -1 &&
6464
process.env.NODE_ENV === 'test'
6565
) {
6666
jsdomPath = 'file://' + path.resolve('./static/js/jsdom-4.0.0.min.js');

packages/app/src/sandbox/eval/transpilers/babel/babel-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function getBabelConfig(
5353
: 'transform-es2015-modules-commonjs';
5454

5555
if (finalConfig.plugins) {
56-
if (!finalConfig.plugins.includes(commonjsPluginName)) {
56+
if (finalConfig.plugins.indexOf(commonjsPluginName) === -1) {
5757
finalConfig.plugins = [...finalConfig.plugins, commonjsPluginName];
5858
}
5959
} else {

packages/app/src/sandbox/eval/transpilers/babel/check.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ function checkComment(match) {
99
// If it's in a comment or string, we're extremely aggressive here because
1010
// transpiling is absolutely our last resort.
1111
if (
12-
startOfLine.includes('//') ||
13-
startOfLine.includes('*') ||
14-
startOfLine.includes("'") ||
15-
startOfLine.includes('"') ||
16-
startOfLine.includes('`')
12+
startOfLine.indexOf('//') > -1 ||
13+
startOfLine.indexOf('*') > -1 ||
14+
startOfLine.indexOf("'") > -1 ||
15+
startOfLine.indexOf('"') > -1 ||
16+
startOfLine.indexOf('`') > -1
1717
) {
1818
return false;
1919
}

packages/app/src/sandbox/eval/transpilers/babel/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class BabelTranspiler extends WorkerTranspiler {
8989
const isV7 =
9090
loaderContext.options.isV7 || isBabel7(dependencies, devDependencies);
9191

92-
const hasMacros = Object.keys(dependencies).some(d =>
93-
d.includes('macro')
92+
const hasMacros = Object.keys(dependencies).some(
93+
d => d.indexOf('macro') > -1
9494
);
9595

9696
const babelConfig = getBabelConfig(

packages/app/src/sandbox/eval/transpilers/babel/worker/babel-worker.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ self.require = path => {
6565
return module;
6666
}
6767

68-
if (IGNORED_MODULES.includes(path)) {
68+
if (IGNORED_MODULES.indexOf(path) > -1) {
6969
return {};
7070
}
7171

@@ -340,13 +340,13 @@ async function compile(code, customConfig, path, isV7) {
340340
} catch (e) {
341341
if (
342342
!fsInitialized &&
343-
(e.message.includes('Cannot find module') || e.code === 'EIO')
343+
(e.message.indexOf('Cannot find module') > -1 || e.code === 'EIO')
344344
) {
345345
// BrowserFS was needed but wasn't initialized
346346
await waitForFs();
347347

348348
await compile(code, customConfig, path);
349-
} else if (e.message.includes('Cannot find module')) {
349+
} else if (e.message.indexOf('Cannot find module') > -1) {
350350
// Try to download the file and all dependencies, retry compilation then
351351
await downloadFromError(e).then(() => {
352352
resetCache();
@@ -504,19 +504,19 @@ self.addEventListener('message', async event => {
504504

505505
if (!disableCodeSandboxPlugins) {
506506
if (
507-
flattenedPresets.includes('env') &&
508-
!Object.keys(Babel.availablePresets).includes('env') &&
507+
flattenedPresets.indexOf('env') > -1 &&
508+
Object.keys(Babel.availablePresets).indexOf('env') === -1 &&
509509
version !== 7
510510
) {
511511
Babel.registerPreset('env', Babel.availablePresets.latest);
512512
}
513513

514514
if (
515515
version === 7 &&
516-
!Object.keys(Babel.availablePresets).includes('env') &&
517-
(flattenedPresets.includes('env') ||
518-
flattenedPresets.includes('@babel/preset-env') ||
519-
flattenedPresets.includes('@vue/app'))
516+
Object.keys(Babel.availablePresets).indexOf('env') === -1 &&
517+
(flattenedPresets.indexOf('env') > -1 ||
518+
flattenedPresets.indexOf('@babel/preset-env') > -1 ||
519+
flattenedPresets.indexOf('@vue/app') > -1)
520520
) {
521521
const envPreset = await import(
522522
/* webpackChunkName: 'babel-preset-env' */ '@babel/preset-env'
@@ -525,8 +525,8 @@ self.addEventListener('message', async event => {
525525
}
526526

527527
if (
528-
flattenedPlugins.includes('transform-vue-jsx') &&
529-
!Object.keys(Babel.availablePlugins).includes('transform-vue-jsx')
528+
flattenedPlugins.indexOf('transform-vue-jsx') > -1 &&
529+
Object.keys(Babel.availablePlugins).indexOf('transform-vue-jsx') === -1
530530
) {
531531
const vuePlugin = await import(
532532
/* webpackChunkName: 'babel-plugin-transform-vue-jsx' */ 'babel-plugin-transform-vue-jsx'
@@ -535,8 +535,8 @@ self.addEventListener('message', async event => {
535535
}
536536

537537
if (
538-
flattenedPlugins.includes('jsx-pragmatic') &&
539-
!Object.keys(Babel.availablePlugins).includes('jsx-pragmatic')
538+
flattenedPlugins.indexOf('jsx-pragmatic') > -1 &&
539+
Object.keys(Babel.availablePlugins).indexOf('jsx-pragmatic') === -1
540540
) {
541541
const pragmaticPlugin = await import(
542542
/* webpackChunkName: 'babel-plugin-jsx-pragmatic' */ 'babel-plugin-jsx-pragmatic'
@@ -545,8 +545,8 @@ self.addEventListener('message', async event => {
545545
}
546546

547547
if (
548-
flattenedPlugins.includes('babel-plugin-macros') &&
549-
!Object.keys(Babel.availablePlugins).includes('babel-plugin-macros')
548+
flattenedPlugins.indexOf('babel-plugin-macros') > -1 &&
549+
Object.keys(Babel.availablePlugins).indexOf('babel-plugin-macros') === -1
550550
) {
551551
if (hasMacros) {
552552
await waitForFs();
@@ -556,8 +556,8 @@ self.addEventListener('message', async event => {
556556
}
557557

558558
if (
559-
flattenedPlugins.includes('transform-cx-jsx') &&
560-
!Object.keys(Babel.availablePlugins).includes('transform-cx-jsx')
559+
flattenedPlugins.indexOf('transform-cx-jsx') > -1 &&
560+
Object.keys(Babel.availablePlugins).indexOf('transform-cx-jsx') === -1
561561
) {
562562
const cxJsxPlugin = await import(
563563
/* webpackChunkName: 'transform-cx-jsx' */ 'babel-plugin-transform-cx-jsx'

packages/app/src/sandbox/eval/transpilers/babel/worker/dynamic-download.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function mkDirByPathSync(targetDir, { isRelativeToScript = false } = {}) {
2626
throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
2727
}
2828

29-
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].includes(err.code);
29+
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
3030
if (!caughtErr || (caughtErr && curDir === path.resolve(targetDir))) {
3131
throw err; // Throw if it's just the last created dir.
3232
}
@@ -158,7 +158,7 @@ export async function downloadPath(absolutePath) {
158158
}
159159

160160
export async function downloadFromError(e) {
161-
if (e.message.includes('Cannot find module')) {
161+
if (e.message.indexOf('Cannot find module') > -1) {
162162
return new Promise(res => {
163163
const dep = e.message.match(/Cannot find module '(.*?)'/)[1];
164164
const from = e.message.match(/from '(.*?)'/)[1];

packages/app/src/sandbox/eval/transpilers/reason/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function getDependencyList(
5050
const deps =
5151
cache ||
5252
listFunction(module.code)
53-
.filter(x => !IGNORED_DEPENDENCIES.includes(x))
53+
.filter(x => IGNORED_DEPENDENCIES.indexOf(x) === -1)
5454
.filter(x => !list.has(x));
5555

5656
if (!cache) {

packages/app/src/sandbox/eval/transpilers/sass/worker/sass-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const existsPromise = (fs, file) =>
6767

6868
const ext = extname(path).substr(1);
6969

70-
if (!SUPPORTED_EXTS.includes(ext)) {
70+
if (SUPPORTED_EXTS.indexOf(ext) === -1) {
7171
r(false);
7272
return;
7373
}

0 commit comments

Comments
 (0)