Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/webpack5/__tests__/loaders/native-class-loaders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,23 @@ export class FooImpl extends NSObject {
INPUT_TS,
);
});

it('keeps a statement without semicolon apart from the downleveled class', async () => {
const input = `const a = 1
/*__NativeClass__*/
class Foo extends NSObject {}
`;
const output = await new Promise<string>((resolve) =>
downlevelLoader.call(createDownlevelContext(resolve), input),
);
const { diagnostics } = ts.transpileModule(output, {
fileName: '/check.js',
reportDiagnostics: true,
});
const errors = diagnostics.map((d) =>
ts.flattenDiagnosticMessageText(d.messageText, '\n'),
);
expect(errors).toEqual([]);
expect(output).toMatch(/const a = 1\s*\n\s*var /);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Candidate {
interface DownleveledClass {
code: string;
map: any;
// Lines added in front of the transpiled class (the IIFE wrapper).
// Lines added in front of the transpiled class (separator newline and IIFE wrapper).
leadingLines: number;
}

Expand Down Expand Up @@ -106,6 +106,9 @@ function downlevelClass(
} catch (e) {
// ignore parsing safety guard failures – fallback to raw transpiled
}
// transpileModule drops the leading newline; keep statements apart.
transpiled = `\n${transpiled}`;
leadingLines += 1;
if (process.env.NATIVECLASS_DEBUG) {
loader.emitWarning(
new Error(
Expand Down