aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-13 20:56:22 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-13 20:56:22 -0700
commit4f0d4cee0be523bcaeaa85e80309526bdf5cd91e (patch)
tree8d967c3c6034c5c5ba31334a129863da08ee85c9 /src
parenta0b6892c09df396e92ce02413f0f83f214aae985 (diff)
downloadbun-4f0d4cee0be523bcaeaa85e80309526bdf5cd91e.tar.gz
bun-4f0d4cee0be523bcaeaa85e80309526bdf5cd91e.tar.zst
bun-4f0d4cee0be523bcaeaa85e80309526bdf5cd91e.zip
Feature flag auto_import_buffer since it's not fully implemented yetnot-quite-v0
Diffstat (limited to 'src')
-rw-r--r--src/feature_flags.zig1
-rw-r--r--src/js_parser/js_parser.zig43
2 files changed, 25 insertions, 19 deletions
diff --git a/src/feature_flags.zig b/src/feature_flags.zig
index b08bfbc0d..a79e1b9b6 100644
--- a/src/feature_flags.zig
+++ b/src/feature_flags.zig
@@ -66,3 +66,4 @@ pub const CSSInJSImportBehavior = enum {
// having issues compiling WebKit with this enabled
pub const remote_inspector = false;
+pub const auto_import_buffer = false;
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index e7e494143..3312a84ed 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -2342,24 +2342,26 @@ pub const Parser = struct {
var runtime_imports_iter = p.runtime_imports.iter();
- // If they use Buffer...just automatically import it.
- // ✨ magic ✨ (i don't like this)
- if (p.symbols.items[p.buffer_ref.inner_index].use_count_estimate > 0) {
- var named_import = p.named_imports.getOrPut(p.buffer_ref);
-
- // if Buffer is actually an import, let them use that one instead.
- if (!named_import.found_existing) {
- const import_record_id = p.addImportRecord(
- .require,
- logger.Loc.empty,
- NodeFallbacks.buffer_fallback_import_name,
- );
- var import_stmt = p.s(S.Import{
- .namespace_ref = p.buffer_ref,
- .star_name_loc = loc,
- .is_single_line = true,
- .import_record_index = import_record_id,
- }, loc);
+ if (FeatureFlags.auto_import_buffer) {
+ // If they use Buffer...just automatically import it.
+ // ✨ magic ✨ (i don't like this)
+ if (p.symbols.items[p.buffer_ref.inner_index].use_count_estimate > 0) {
+ var named_import = p.named_imports.getOrPut(p.buffer_ref);
+
+ // if Buffer is actually an import, let them use that one instead.
+ if (!named_import.found_existing) {
+ const import_record_id = p.addImportRecord(
+ .require,
+ logger.Loc.empty,
+ NodeFallbacks.buffer_fallback_import_name,
+ );
+ var import_stmt = p.s(S.Import{
+ .namespace_ref = p.buffer_ref,
+ .star_name_loc = loc,
+ .is_single_line = true,
+ .import_record_index = import_record_id,
+ }, loc);
+ }
}
}
@@ -3537,7 +3539,10 @@ pub fn NewParser(
p.exports_ref = try p.declareCommonJSSymbol(.unbound, "exports");
p.module_ref = try p.declareCommonJSSymbol(.unbound, "module");
p.require_ref = try p.declareCommonJSSymbol(.unbound, "require");
- p.buffer_ref = try p.declareCommonJSSymbol(.unbound, "Buffer");
+
+ if (FeatureFlags.auto_import_buffer) {
+ p.buffer_ref = try p.declareCommonJSSymbol(.unbound, "Buffer");
+ }
if (p.options.enable_bundling) {
p.runtime_imports.__reExport = try p.declareGeneratedSymbol(.other, "__reExport");