diff --git a/packages/metro-bundler/src/JSTransformer/worker/__tests__/worker-test.js b/packages/metro-bundler/src/JSTransformer/worker/__tests__/worker-test.js index da0aa494..451854a8 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/__tests__/worker-test.js +++ b/packages/metro-bundler/src/JSTransformer/worker/__tests__/worker-test.js @@ -164,7 +164,7 @@ describe('code transformation worker:', () => { {}, error => { expect(error).toBeNull(); - expect(extractDependencies).toBeCalledWith(code); + expect(extractDependencies).toBeCalledWith(code, 'filename'); done(); }, ); @@ -282,7 +282,7 @@ describe('code transformation worker:', () => { it('Uses the code obtained from `constant-folding` to extract dependencies', done => { transformCode(transformer, filename, filename, 'code', options, () => { - expect(extractDependencies).toBeCalledWith(foldedCode); + expect(extractDependencies).toBeCalledWith(foldedCode, filename); done(); }); }); diff --git a/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js b/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js index 1fbe706e..2f9a02df 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js +++ b/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js @@ -28,7 +28,8 @@ const babylon = require('babylon'); * because it ignores that the scope may have reassigned or shadowed that value, * but it's a tradeoff for simplicity. */ -function extractDependencies(code: string) { + +function extractDependencies(code: string, filename: string) { const ast = babylon.parse(code, {sourceType: 'module'}); const dependencies = new Set(); const dependencyOffsets = []; @@ -40,7 +41,10 @@ function extractDependencies(code: string) { if (parentType === 'TryStatement') { return; } - throw new Error('require() must have a single string literal argument'); + throw new Error( + `require() must have a single string literal argument: ${filename}:${arg + .loc.start.line - 1}`, + ); } dependencyOffsets.push(arg.start); dependencies.add(arg.value); diff --git a/packages/metro-bundler/src/JSTransformer/worker/index.js b/packages/metro-bundler/src/JSTransformer/worker/index.js index a25913f7..37e2c3f7 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/index.js +++ b/packages/metro-bundler/src/JSTransformer/worker/index.js @@ -143,7 +143,7 @@ const transformCode: TransformCode = asyncify( const depsResult = isJson ? {dependencies: [], dependencyOffsets: []} - : extractDependencies(code); + : extractDependencies(code, filename); const timeDelta = process.hrtime( transformFileStartLogEntry.start_timestamp,