Skip to content

Commit 2decc8a

Browse files
fix: ensure import/export sources are not template literals
1 parent 731c0df commit 2decc8a

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/stages/main/patchers/StringPatcher.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { SourceType } from 'coffee-lex';
22
import { PatchOptions } from '../../../patchers/types';
33

4+
import ExportAllDeclarationPatcher from './ExportAllDeclarationPatcher';
5+
import ExportBindingsDeclarationPatcher from './ExportBindingsDeclarationPatcher';
6+
import ImportDeclarationPatcher from './ImportDeclarationPatcher';
47
import InterpolatedPatcher from './InterpolatedPatcher';
58

69
/**
@@ -38,6 +41,16 @@ export default class StringPatcher extends InterpolatedPatcher {
3841
}
3942

4043
shouldBecomeTemplateLiteral(): boolean {
44+
if (
45+
(this.parent instanceof ImportDeclarationPatcher ||
46+
this.parent instanceof ExportAllDeclarationPatcher ||
47+
this.parent instanceof ExportBindingsDeclarationPatcher) &&
48+
this.parent.source === this
49+
) {
50+
// Import sources should never be template literals.
51+
return false;
52+
}
53+
4154
return this.expressions.length > 0 || this.node.raw.indexOf('\n') > -1;
4255
}
4356
}

test/import_test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,25 @@ describe('imports', () => {
227227
`
228228
);
229229
});
230+
231+
it('does not convert an import source to a template literal (#1368)', () => {
232+
check(
233+
`
234+
import """stupid file name
235+
"""
236+
export * from """another stupid file name
237+
"""
238+
export { a } from """a third stupid file name
239+
"""
240+
`,
241+
`
242+
import "stupid file name\\
243+
";
244+
export * from "another stupid file name\\
245+
";
246+
export { a } from "a third stupid file name\\
247+
";
248+
`
249+
);
250+
});
230251
});

0 commit comments

Comments
 (0)