From 62fb5ea9e396c5296f845d32f1aae5629fbf5836 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 15 Dec 2021 15:16:53 -0800 Subject: wip fix live bindings --- src/js_parser/js_parser.zig | 309 ++++++++++++++++++++------------------------ 1 file changed, 139 insertions(+), 170 deletions(-) (limited to 'src/js_parser/js_parser.zig') diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 38ce0f270..4d10c0b5e 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -20,6 +20,8 @@ const ScopeOrderList = std.ArrayListUnmanaged(?ScopeOrder); const JSXFactoryName = "JSX"; const JSXAutomaticName = "jsx_module"; +// kept as a static reference +const exports_string_name: string = "exports"; const MacroRefs = std.AutoArrayHashMap(Ref, u32); // If we are currently in a hoisted child of the module scope, relocate these @@ -437,124 +439,77 @@ pub const ImportScanner = struct { } } - if (p.options.trim_unused_imports) { - if (st.star_name_loc != null or did_remove_star_loc) { - // -- Original Comment -- - // If we're bundling a star import and the namespace is only ever - // used for property accesses, then convert each unique property to - // a clause item in the import statement and remove the star import. - // That will cause the bundler to bundle them more efficiently when - // both this module and the imported module are in the same group. - // - // Before: - // - // import * as ns from 'foo' - // console.log(ns.a, ns.b) - // - // After: - // - // import {a, b} from 'foo' - // console.log(a, b) - // - // This is not done if the namespace itself is used, because in that - // case the code for the namespace will have to be generated. This is - // determined by the symbol count because the parser only counts the - // star import as used if it was used for something other than a - // property access: - // - // import * as ns from 'foo' - // console.log(ns, ns.a, ns.b) - // - // -- Original Comment -- - - // jarred: we don't use the same grouping mechanism as esbuild - // but, we do this anyway. - // The reasons why are: - // * It makes static analysis for other tools simpler. - // * I imagine browsers may someday do some optimizations - // when it's "easier" to know only certain modules are used - // For example, if you're importing a component from a design system - // it's really stupid to import all 1,000 components from that design system - // when you just want