Skip to content

Commit 976312c

Browse files
committed
Fix types
1 parent 6fe3f71 commit 976312c

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

packages/app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@
248248
"@graphql-codegen/typescript-graphql-files-modules": "^1.8.2",
249249
"@graphql-codegen/typescript-operations": "^1.8.2",
250250
"@sentry/cli": "^1.47.1",
251-
"@types/astring": "^1.3.0",
252251
"@types/codemirror": "^0.0.72",
253252
"@types/debug": "^4.1.1",
254253
"@types/gsap": "^1.20.1",

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ describe('convert-esmodule', () => {
55
const code = `
66
export * from './test/store.js';
77
`;
8-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
8+
expect(convertEsModule(code)).toMatchSnapshot();
99
});
1010

1111
it('can convert normal exports', () => {
1212
const code = `
1313
export { test, test2 } from './test/store.js';
1414
`;
15-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
15+
expect(convertEsModule(code)).toMatchSnapshot();
1616
});
1717

1818
it('can convert function exports', () => {
@@ -21,63 +21,63 @@ describe('convert-esmodule', () => {
2121
export const test2 = () => {}
2222
export class Test {}
2323
`;
24-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
24+
expect(convertEsModule(code)).toMatchSnapshot();
2525
});
2626

2727
it('can convert default exports', () => {
2828
const code = `
2929
export default function test() {}
3030
`;
31-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
31+
expect(convertEsModule(code)).toMatchSnapshot();
3232
});
3333

3434
it('can convert class default exports', () => {
3535
const code = `
3636
export default class A {}
3737
`;
38-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
38+
expect(convertEsModule(code)).toMatchSnapshot();
3939
});
4040

4141
it('can convert weird default exports', () => {
4242
const code = `
4343
export default a = 'b';
4444
`;
45-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
45+
expect(convertEsModule(code)).toMatchSnapshot();
4646
});
4747

4848
it('can convert default imports', () => {
4949
const code = `
5050
import a from './b';
5151
`;
52-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
52+
expect(convertEsModule(code)).toMatchSnapshot();
5353
});
5454

5555
it('can convert named imports', () => {
5656
const code = `
5757
import {a, b, c} from './b';
5858
`;
59-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
59+
expect(convertEsModule(code)).toMatchSnapshot();
6060
});
6161

6262
it('can handle as imports', () => {
6363
const code = `
6464
import { a as b } from './b';
6565
`;
66-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
66+
expect(convertEsModule(code)).toMatchSnapshot();
6767
});
6868

6969
it('ignores comments', () => {
7070
const code = `
7171
// import { a as b } from './b';
7272
`;
73-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
73+
expect(convertEsModule(code)).toMatchSnapshot();
7474
});
7575

7676
it('can handle inline comments', () => {
7777
const code = `
7878
import { a as b, /* HELLO WORLD */ c } from './b';
7979
`;
80-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
80+
expect(convertEsModule(code)).toMatchSnapshot();
8181
});
8282

8383
it('can handle class properties', () => {
@@ -92,7 +92,7 @@ describe('convert-esmodule', () => {
9292
static d = ''
9393
}
9494
`;
95-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
95+
expect(convertEsModule(code)).toMatchSnapshot();
9696
});
9797

9898
it('can handle async code', () => {
@@ -102,17 +102,19 @@ describe('convert-esmodule', () => {
102102
const test = await test2()
103103
}
104104
`;
105-
expect(convertEsModule('/index.js', code)).toMatchSnapshot();
105+
expect(convertEsModule(code)).toMatchSnapshot();
106106
});
107107

108108
it.skip('has good perf', () => {
109+
/* eslint-disable */
109110
const code = require('./big-file');
110111

111112
const t = Date.now();
112113

113114
for (let i = 0; i < 1; i++) {
114-
convertEsModule('/index.js', code);
115+
convertEsModule(code);
115116
}
116117
console.log(Date.now() - t);
118+
/* eslint-enable */
117119
});
118120
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import * as meriyah from 'meriyah';
44
import * as astring from 'astring';
55
import { basename } from 'path';
6-
import { measure, endMeasure } from '../../../../utils/metrics';
76
import { Syntax as n } from './syntax';
87
import {
98
generateRequireStatement,
@@ -17,7 +16,7 @@ import { customGenerator } from './generator';
1716
/**
1817
* Converts esmodule code to commonjs code, built to be as fast as possible
1918
*/
20-
export function convertEsModule(path: string, code: string) {
19+
export function convertEsModule(code: string) {
2120
const usedVarNames = [];
2221

2322
const getVarName = (name: string) => {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ class BabelTranspiler extends WorkerTranspiler {
4949
): Promise<{ transpiledCode: string }> {
5050
return new Promise((resolve, reject) => {
5151
const { path } = loaderContext;
52+
let newCode = code;
5253

53-
if (isESModule(code) && path.indexOf('/node_modules') > -1) {
54+
if (isESModule(newCode) && path.indexOf('/node_modules') > -1) {
5455
try {
5556
measure(`es-${path}`);
56-
code = convertEsModule(path, code);
57+
newCode = convertEsModule(newCode);
5758
endMeasure(`es-${path}`);
5859
} catch (e) {
5960
console.warn(
@@ -69,9 +70,9 @@ class BabelTranspiler extends WorkerTranspiler {
6970
if (
7071
(loaderContext.options.simpleRequire ||
7172
path.startsWith('/node_modules')) &&
72-
!shouldTranspile(code, path)
73+
!shouldTranspile(newCode, path)
7374
) {
74-
regexGetRequireStatements(code).forEach(dependency => {
75+
regexGetRequireStatements(newCode).forEach(dependency => {
7576
if (dependency.isGlob) {
7677
loaderContext.addDependenciesInDirectory(dependency.path);
7778
} else {
@@ -80,7 +81,7 @@ class BabelTranspiler extends WorkerTranspiler {
8081
});
8182

8283
resolve({
83-
transpiledCode: code,
84+
transpiledCode: newCode,
8485
});
8586
return;
8687
}
@@ -119,7 +120,7 @@ class BabelTranspiler extends WorkerTranspiler {
119120

120121
this.queueTask(
121122
{
122-
code,
123+
code: newCode,
123124
config: babelConfig,
124125
path,
125126
loaderOptions,

yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,14 +3943,6 @@
39433943
resolved "https://registry.yarnpkg.com/@types/asap/-/asap-2.0.0.tgz#d529e9608c83499a62ae08c871c5e62271aa2963"
39443944
integrity sha512-upIS0Gt9Mc8eEpCbYMZ1K8rhNosfKUtimNcINce+zLwJF5UpM3Vv7yz3S5l/1IX+DxTa8lTkUjqynvjRXyJzsg==
39453945

3946-
"@types/astring@^1.3.0":
3947-
version "1.3.0"
3948-
resolved "https://registry.yarnpkg.com/@types/astring/-/astring-1.3.0.tgz#c576a8eba50592d707e78dccd2aa50513f0c1866"
3949-
integrity sha512-PYUIKAlUl95QIoWrvTW1aj5YJoiBLukCixTBKkVMq17BbkcX4I6Yn7lkltzsM3fXByV4l2x4tJGYhHqyYnhH4A==
3950-
dependencies:
3951-
"@types/estree" "*"
3952-
"@types/node" "*"
3953-
39543946
"@types/babel__core@^7.1.0":
39553947
version "7.1.2"
39563948
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f"

0 commit comments

Comments
 (0)