Skip to content

Commit 2019dcc

Browse files
committed
Preserve hash aliases during compiler analysis
1 parent 1d89c8a commit 2019dcc

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'octane': patch
3+
---
4+
5+
Preserve leading Node package-import aliases in compiler analysis filenames.

‎packages/octane/src/compiler/compile.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,7 @@ function restampAuthoredStyleHashes(ast, styleRemap, filename) {
42854285

42864286
function cleanCompileFilename(filename) {
42874287
const query = filename.indexOf('?');
4288-
const hash = filename.indexOf('#');
4288+
const hash = filename.indexOf('#', filename.startsWith('#') ? 1 : 0);
42894289
let end = filename.length;
42904290
if (query !== -1) end = query;
42914291
if (hash !== -1 && hash < end) end = hash;

‎packages/octane/tests/bundler-compiler.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ describe('bundler-neutral compiler integration', () => {
9191
expect(canonicalModuleId('#nitro/virtual/polyfills', root)).toBe('#nitro/virtual/polyfills');
9292
});
9393

94+
it('preserves package-import aliases in authored diagnostics', () => {
95+
const compiler = createOctaneCompiler({ root: '/project' });
96+
let thrown: unknown;
97+
try {
98+
compiler.transform(
99+
'export function Button() { <button>unused</button>; return null; }',
100+
'#components/Button.tsrx?octane-hydrate=0',
101+
);
102+
} catch (error) {
103+
thrown = error;
104+
}
105+
expect(thrown).toMatchObject({ fileName: '#components/Button.tsrx' });
106+
});
107+
94108
it('compiles the same source for client and server with maps', () => {
95109
const compiler = createOctaneCompiler({ root: '/project' });
96110
const client = compiler.transform(COMPONENT, '/project/src/App.tsrx?v=1', {

0 commit comments

Comments
 (0)