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

feat(compiler): compiler returns import locations #139

Conversation

apapko
Copy link
Collaborator

@apapko apapko commented Mar 7, 2018

Details

Compiler's bundle result object will return list of module import locations

export interface ImportLocation {
    name: string;
    location: {
        start: number;
        length: number;
    };
}

Does this PR introduce a breaking change?

  • Yes
  • No

@apapko apapko requested a review from pmdartus March 7, 2018 01:08
getLocations(code: string): ImportLocation[] {
const locations: ImportLocation[] = [];

if (!code) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed.

@@ -0,0 +1,66 @@
export interface ImportLocation {
name: string;
location: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Location interface instead of inlining the type here.

const QUOTE_LENGTH = 1;
const MODULE_IMPORT_REGEX = /(?<=define\()('.*?', )\[('.*?')\]/;

export class ImportLocationCollector {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a class since the only exposed method getLocation is stateless?
In this context, a simple function would make more sense.

return {
diagnostics,
code,
map: null,
metadata: metadataCollector.getMetadata()
metadata: metadataCollector.getMetadata(),
importLocations,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation behind adding importLocations property to the BundleReport instead of Metadata?

export interface BundleReport {
code: string;
diagnostics: Diagnostic[];
map: null;
metadata: BundleMetadata;
importLocations: ImportLocation[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ModuleImportLocations instead of ImportLocation[] since the same type is defined below.

// 1. full match
// 2. filename
// 3. imports
if (!matches || matches.length < EXPECTED_MATCH_LENGTH) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it worth logging a warning if the getLocations can't even match the define( prefix for AMD. Since the compiler expects this specific format.

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 7c91533 | Target commit: dffa9a9

benchmark base(7c91533) target(dffa9a9) trend
table-append-1k.benchmark:benchmark-table/append/1k 272.77 (± 2.62 ms) 268.65 (± 3.01 ms) 👍
table-clear-1k.benchmark:benchmark-table/clear/1k 13.53 (± 0.54 ms) 13.78 (± 0.53 ms) 👌
table-create-10k.benchmark:benchmark-table/create/10k 1516.63 (± 10.28 ms) 1502.41 (± 12.06 ms) 👌
table-create-1k.benchmark:benchmark-table/create/1k 162.79 (± 2.83 ms) 169.72 (± 3.40 ms) 👎
table-update-10th-1k.benchmark:benchmark-table/update-10th/1k 138.72 (± 3.56 ms) 150.81 (± 4.70 ms) 👎
tablecmp-append-1k.benchmark:benchmark-table-component/append/1k 356.64 (± 4.73 ms) 332.64 (± 12.76 ms) 👍
tablecmp-clear-1k.benchmark:benchmark-table/clear/1k 34.90 (± 1.15 ms) 33.90 (± 1.56 ms) 👍
tablecmp-create-10k.benchmark:benchmark-table-component/create/10k 2668.68 (± 20.22 ms) 2354.74 (± 21.45 ms) 👍
tablecmp-create-1k.benchmark:benchmark-table-component/create/1k 293.61 (± 4.44 ms) 261.87 (± 2.81 ms) 👍
tablecmp-update-10th-1k.benchmark:benchmark-table-component/update-10th/1k 150.71 (± 3.35 ms) 143.38 (± 2.75 ms) 👍

@apapko
Copy link
Collaborator Author

apapko commented Mar 19, 2018

@pmdartus please review when you get a chance

@apapko apapko merged commit 61c93d0 into apapko/raptor-on-platform-compiler Mar 22, 2018
@apapko apapko deleted the apapko/compiler-import-location-references branch March 22, 2018 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants