Skip to content

Commit

Permalink
Don't get stuck on syntax errors in newly added files
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D16090159

fbshipit-source-id: dc0bdae557a01cb229be202a02afed70fab6c7e5
  • Loading branch information
gaearon authored and facebook-github-bot committed Jul 2, 2019
1 parent dc2f29f commit 118f1f8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,43 @@ it('should retry to traverse the dependencies as it was after getting an error',
).rejects.toBeInstanceOf(Error);
});

it('should retry traversing dependencies after a transform error', async () => {
function BadError() {}

const localOptions = {
...options,
transform(path) {
if (path === '/bad') {
throw new BadError();
}
return options.transform.apply(this, arguments);
},
};

await initialTraverseDependencies(graph, localOptions);

Actions.createFile('/bad');
Actions.addDependency('/foo', '/bad');

await expect(
traverseDependencies(['/foo'], graph, localOptions),
).rejects.toBeInstanceOf(BadError);

// Repeated attempt should give the same error.
await expect(
traverseDependencies(['/foo'], graph, localOptions),
).rejects.toBeInstanceOf(BadError);

// Finally, pass normal `options` that don't reject the '/bad' module:
expect(
getPaths(await traverseDependencies([...files], graph, options)),
).toEqual({
added: new Set(['/bad']),
modified: new Set(['/foo']),
deleted: new Set(),
});
});

describe('Progress updates', () => {
it('calls back for each finished module', async () => {
const onProgress = jest.fn();
Expand Down
10 changes: 8 additions & 2 deletions packages/metro/src/DeltaBundler/traverseDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,14 @@ async function processModule<T>(
}
}

await Promise.all(promises);

try {
await Promise.all(promises);
} catch (err) {
// If there is an error, restore the previous dependency list.
// This ensures we don't skip over them during the next traversal attempt.
module.dependencies = previousDependencies;
throw err;
}
return module;
}

Expand Down

0 comments on commit 118f1f8

Please sign in to comment.