Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): correct module-resolver error messages @bug W-5192589@ #551

Merged
merged 7 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion packages/lwc-compiler/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ describe("test index entry points", () => {
const { success, diagnostics } = await compile(config);
expect(success).toBe(false);
expect(diagnostics.length).toBe(1);
expect(diagnostics[0].message).toBe("Could not resolve 'foo' (as foo.js) from compiler entry point");
expect(diagnostics[0].message).toBe("Failed to resolve entry for module foo");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe("compiler result", () => {
const { level, message } = diagnostics[0];

expect(level).toBe(DiagnosticLevel.Fatal);
expect(message).toContain('Could not resolve \'./nothing\' (as nothing.js) from \'foo.js\'');
expect(message).toContain('./nothing failed to be resolved from foo.js');
});

test('compiler returns diagnostic errors when transformation encounters an error in javascript', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { compile } from "../../compiler/compiler";
import { DiagnosticLevel } from "../../diagnostics/diagnostic";
import { pretify, readFixture } from "../../__tests__/utils";

const VALID_CONFIG = {
Expand Down Expand Up @@ -111,4 +112,48 @@ describe("module resolver", () => {
});`)
);
});

test("compiler should resolve bundle with local import", async () => {
const COMPILER_CONFIG_BASEDIR = {
name: "foo",
namespace: "x",
files: {
"foo.js": `import { nested } from './lib/foo';`,
"lib/foo.js": `export function nested(){ return null;}`
}
};

const { result, success } = await compile(COMPILER_CONFIG_BASEDIR);
expect(success).toBe(true);
expect(result).toBeDefined();
});

test("compiler should report fatal diagnostic if local import cannot be resolved", async () => {
const COMPILER_CONFIG_BASEDIR = {
name: "foo",
namespace: "x",
files: {
"foo.js": `import { nested } from './lib/foo';`,
}
};

const { diagnostics, success } = await compile(COMPILER_CONFIG_BASEDIR);
expect(success).toBe(false);
expect(diagnostics[0].level).toBe(DiagnosticLevel.Fatal);
});

test("compiler should report fatal diagnostic when invalid entry path is specified", async () => {
const COMPILER_CONFIG_BASEDIR = {
name: "modules/foo",
namespace: "x",
files: {
"foo.js": ``,
}
};

const { diagnostics, success } = await compile(COMPILER_CONFIG_BASEDIR);
expect(success).toBe(false);
expect(diagnostics[0].level).toBe(DiagnosticLevel.Fatal);
});

});
4 changes: 2 additions & 2 deletions packages/lwc-compiler/src/rollup-plugins/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export default function({
) {
if (importer) {
throw new CompilerError(
`Could not resolve '${importee}' (as ${absPath}) from '${importer}'`,
`${importee} failed to be resolved from ${importer}`,
importer,
);
}
throw new CompilerError(
`Could not resolve '${importee}' (as ${absPath}) from compiler entry point`,
`Failed to resolve entry for module ${importee}`,
importer,
);
}
Expand Down