Skip to content

Commit e0a47c2

Browse files
committed
Fix case
1 parent 7d991c0 commit e0a47c2

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/app/src/sandbox/eval/transpiled-module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ export default class TranspiledModule {
619619
} else {
620620
const transpilers = manager.preset.getLoaders(this.module, this.query);
621621

622+
const startTime = Date.now();
622623
for (let i = 0; i < transpilers.length; i += 1) {
623624
const transpilerConfig = transpilers[i];
624625
const loaderContext = this.getLoaderContext(
@@ -632,7 +633,6 @@ export default class TranspiledModule {
632633
.join('!');
633634

634635
try {
635-
const startTime = Date.now();
636636
const {
637637
transpiledCode,
638638
sourceMap,
@@ -641,9 +641,6 @@ export default class TranspiledModule {
641641
code,
642642
loaderContext
643643
);
644-
debug(
645-
`Transpiled '${this.getId()}' in ${Date.now() - startTime}ms`
646-
);
647644

648645
if (this.errors.length) {
649646
throw this.errors[0];
@@ -664,6 +661,7 @@ export default class TranspiledModule {
664661
throw e;
665662
}
666663
}
664+
debug(`Transpiled '${this.getId()}' in ${Date.now() - startTime}ms`);
667665

668666
this.logWarnings();
669667
}

packages/app/src/sandbox/eval/transpilers/babel/convert-esmodule.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,21 @@ export function convertEsModule(path: string, code: string) {
438438
let importName: string;
439439

440440
if (specifier.type === n.ImportDefaultSpecifier) {
441+
// import Test from 'test';
441442
// const _test = require('test');
442-
// var default = _test.default;
443-
localName = 'default';
443+
// var Test = _test.default;
444+
localName = specifier.local.name;
444445
importName = 'default';
445446
} else if (specifier.type === n.ImportSpecifier) {
447+
// import {Test} from 'test';
446448
// const _test = require('test');
447-
// var $localName = _test.$importName;
449+
// var Test = _test.Test;
448450
localName = specifier.local.name;
449451
importName = specifier.imported.name;
450452
} else if (specifier.type === n.ImportNamespaceSpecifier) {
453+
// import * as Test from 'test';
451454
// const _test = require('test');
452-
// var $localName = _test;
455+
// var Test = _test;
453456
localName = specifier.local.name;
454457
importName = null;
455458
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import BabelWorker from 'worker-loader?publicPath=/&name=babel-transpiler.[hash:
55
import { isBabel7 } from '@codesandbox/common/lib/utils/is-babel-7';
66

77
import isESModule from 'sandbox/eval/utils/is-es-module';
8+
import { measure, endMeasure } from 'sandbox/utils/metrics';
89
import regexGetRequireStatements from './worker/simple-get-require-statements';
910
import getBabelConfig from './babel-parser';
1011
import WorkerTranspiler from '../worker-transpiler';
@@ -50,7 +51,9 @@ class BabelTranspiler extends WorkerTranspiler {
5051
const { path } = loaderContext;
5152

5253
if (isESModule(code) && path.indexOf('/node_modules') > -1) {
54+
measure(`es-${path}`);
5355
code = convertEsModule(path, code);
56+
endMeasure(`es-${path}`);
5457
}
5558

5659
// When we find a node_module that already is commonjs we will just get the

0 commit comments

Comments
 (0)