Skip to content

Commit

Permalink
Fix error for modules parsed as scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhoosreddy committed Nov 9, 2019
1 parent c330fa3 commit 449f84b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/run-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ function getExpected({ attrs }) {

async function runTest(agent, test) {
let { attrs, contents, file } = test;
const isModule = attrs.flags.module;

try {
contents = transpile(contents, attrs.features);
contents = transpile(contents, attrs.features, isModule);
} catch (error) {
return { result: "parser error", error };
}
Expand Down Expand Up @@ -146,9 +147,11 @@ class RethrownError extends ExtendedError {
if (!error) throw new Error('RethrownError requires an error');
this.original = error;
this.new_stack = this.stack;
const errorStackString = error.stack && (typeof error.stack === 'string' ?
error.stack : error.stack.map(location => location.source).join('\n'));
let message_lines = (this.message.match(/\n/g) || []).length + 1;
this.stack = `${this.name}: ${this.message}\n${
this.stack.split('\n').slice(0, message_lines + 1).join('\n')
}\n${error.stack.map(location => location.source).join('\n')}`;
}\n${errorStackString}`;
}
}
8 changes: 4 additions & 4 deletions lib/run-tests/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getBabelPlugins = require("./get-babel-plugins");

const configCaches = new Map();

function getOptions(features) {
function getOptions(features, isModule) {
const featureKey = JSON.stringify(features);
let config = configCaches.get(featureKey);
if (config !== undefined) {
Expand All @@ -17,13 +17,13 @@ function getOptions(features) {
configFile: false,
presets: [[presetEnv, { spec: true }]],
plugins: getBabelPlugins(features),
sourceType: "script",
sourceType: isModule ? "module" : "script",
});

configCaches.set(featureKey, config);
return config;
}

module.exports = function transpile(code, features) {
return transformSync(code, getOptions(features)).code;
module.exports = function transpile(code, features, isModule) {
return transformSync(code, getOptions(features, isModule)).code;
};

0 comments on commit 449f84b

Please sign in to comment.