Skip to content

Commit

Permalink
another one approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgiy Abbasov committed Feb 15, 2017
1 parent 8603d49 commit 219fe15
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions src/compiler/es-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,49 @@ export default class ESNextCompiler {
return Module._nodeModulePaths(dir);
}

static _getBabelOptions (filename) {
static _getBabelOptions1 (filename) {
var { presetStage2, transformRuntime, presetEnv } = loadBabelLibs();

// NOTE: "[transformRuntime, { polyfill: false }]" is a workaround for https://github.com/babel/babel/issues/2877
// NOTE: passPrePreset and complex presets is a workaround for https://github.com/babel/babel/issues/2877
// Fixes https://github.com/DevExpress/testcafe/issues/969
return {
passPerPreset: true,
presets: [
{ plugins: transformRuntime },
{
passPerPreset: false,
presets: [presetStage2, presetEnv]
}
],
filename: filename,
sourceMaps: true,
retainLines: true,
ast: false,
babelrc: false,
highlightCode: false,

resolveModuleSource: source => {
if (source === 'testcafe')
return COMMON_API_PATH;

if (BABEL_RUNTIME_RE.test(source)) {
try {
return require.resolve(source);
}
catch (err) {
return source;
}
}

return source;
}
};
}

static _getBabelOptions2 (filename) {
var { presetStage2, transformRuntime, presetEnv } = loadBabelLibs();

// NOTE: passPrePreset and complex presets is a workaround for https://github.com/babel/babel/issues/2877
// Fixes https://github.com/DevExpress/testcafe/issues/969
return {
presets: [presetStage2, presetEnv],
Expand Down Expand Up @@ -65,8 +104,8 @@ export default class ESNextCompiler {

static _isNodeModulesDep (filename) {
return relative(CWD, filename)
.split(pathSep)
.indexOf('node_modules') >= 0;
.split(pathSep)
.indexOf('node_modules') >= 0;
}

static _execAsModule (code, filename) {
Expand Down Expand Up @@ -97,13 +136,16 @@ export default class ESNextCompiler {
if (this.cache[filename])
return this.cache[filename];

var opts = ESNextCompiler._getBabelOptions(filename);
var compiled = babel.transform(code, opts);
var opts1 = ESNextCompiler._getBabelOptions2(filename);
var compiled1 = babel.transform(code, opts1);

var opts2 = ESNextCompiler._getBabelOptions1(filename);
var compiled2 = babel.transform(compiled1.code, opts2);

this.cache[filename] = compiled.code;
this.sourceMaps[filename] = compiled.map;
this.cache[filename] = compiled2.code;
this.sourceMaps[filename] = compiled2.map;

return compiled.code;
return compiled2.code;
}

_setupRequireHook (globals) {
Expand Down

0 comments on commit 219fe15

Please sign in to comment.