Unverified Commit edb19db5 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: visit exports when collecting magic comments (#72422)

Previously, this ignore comment was not respected by Turbopack
```js
export function foo(plugin) {
  return require(/* turbopackIgnore: true */ plugin)
}
```

- Read ignore comments in analyzer test runner for generating
`resolved-effects.snapshot`
- visit exported declarations when collecting magic comments


Closes PACK-3403
parent 9e6d378b
...@@ -19,6 +19,7 @@ use turbopack_core::{ ...@@ -19,6 +19,7 @@ use turbopack_core::{
}; };
use turbopack_ecmascript::analyzer::{ use turbopack_ecmascript::analyzer::{
graph::{create_graph, EvalContext, VarGraph}, graph::{create_graph, EvalContext, VarGraph},
imports::ImportAttributes,
linker::link, linker::link,
test_utils::{early_visitor, visitor}, test_utils::{early_visitor, visitor},
}; };
...@@ -108,7 +109,7 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) { ...@@ -108,7 +109,7 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) {
&input.var_graph, &input.var_graph,
val.clone(), val.clone(),
&early_visitor, &early_visitor,
&(|val| visitor(val, compile_time_info)), &(|val| visitor(val, compile_time_info, ImportAttributes::empty_ref())),
Default::default(), Default::default(),
) )
.await .await
......
...@@ -156,7 +156,7 @@ pub(crate) struct ImportMap { ...@@ -156,7 +156,7 @@ pub(crate) struct ImportMap {
/// ///
/// [magic]: https://webpack.js.org/api/module-methods/#magic-comments /// [magic]: https://webpack.js.org/api/module-methods/#magic-comments
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct ImportAttributes { pub struct ImportAttributes {
/// Should we ignore this import expression when bundling? If so, the import expression will be /// Should we ignore this import expression when bundling? If so, the import expression will be
/// left as-is in Turbopack's output. /// left as-is in Turbopack's output.
/// ///
...@@ -476,14 +476,29 @@ impl Visit for Analyzer<'_> { ...@@ -476,14 +476,29 @@ impl Visit for Analyzer<'_> {
} }
} }
fn visit_export_decl(&mut self, _: &ExportDecl) { fn visit_export_decl(&mut self, n: &ExportDecl) {
self.data.has_exports = true; self.data.has_exports = true;
if self.comments.is_some() {
// only visit children if we potentially need to mark import / requires
n.visit_children_with(self);
}
} }
fn visit_export_default_decl(&mut self, _: &ExportDefaultDecl) { fn visit_export_default_decl(&mut self, n: &ExportDefaultDecl) {
self.data.has_exports = true; self.data.has_exports = true;
if self.comments.is_some() {
// only visit children if we potentially need to mark import / requires
n.visit_children_with(self);
}
} }
fn visit_export_default_expr(&mut self, _: &ExportDefaultExpr) { fn visit_export_default_expr(&mut self, n: &ExportDefaultExpr) {
self.data.has_exports = true; self.data.has_exports = true;
if self.comments.is_some() {
// only visit children if we potentially need to mark import / requires
n.visit_children_with(self);
}
} }
fn visit_program(&mut self, m: &Program) { fn visit_program(&mut self, m: &Program) {
......
...@@ -3845,7 +3845,11 @@ pub mod test_utils { ...@@ -3845,7 +3845,11 @@ pub mod test_utils {
JsValueUrlKind, ModuleValue, WellKnownFunctionKind, WellKnownObjectKind, JsValueUrlKind, ModuleValue, WellKnownFunctionKind, WellKnownObjectKind,
}; };
use crate::{ use crate::{
analyzer::{builtin::replace_builtin, imports::ImportAnnotations, parse_require_context}, analyzer::{
builtin::replace_builtin,
imports::{ImportAnnotations, ImportAttributes},
parse_require_context,
},
utils::module_value_to_well_known_object, utils::module_value_to_well_known_object,
}; };
...@@ -3859,7 +3863,9 @@ pub mod test_utils { ...@@ -3859,7 +3863,9 @@ pub mod test_utils {
pub async fn visitor( pub async fn visitor(
v: JsValue, v: JsValue,
compile_time_info: Vc<CompileTimeInfo>, compile_time_info: Vc<CompileTimeInfo>,
attributes: &ImportAttributes,
) -> Result<(JsValue, bool)> { ) -> Result<(JsValue, bool)> {
let ImportAttributes { ignore, .. } = *attributes;
let mut new_value = match v { let mut new_value = match v {
JsValue::Call( JsValue::Call(
_, _,
...@@ -3923,11 +3929,26 @@ pub mod test_utils { ...@@ -3923,11 +3929,26 @@ pub mod test_utils {
"__dirname" => "__dirname".into(), "__dirname" => "__dirname".into(),
"__filename" => "__filename".into(), "__filename" => "__filename".into(),
"require" => JsValue::WellKnownFunction(WellKnownFunctionKind::Require), "require" => JsValue::unknown_if(
"import" => JsValue::WellKnownFunction(WellKnownFunctionKind::Import), ignore,
JsValue::WellKnownFunction(WellKnownFunctionKind::Require),
true,
"ignored require",
),
"import" => JsValue::unknown_if(
ignore,
JsValue::WellKnownFunction(WellKnownFunctionKind::Import),
true,
"ignored import",
),
"Worker" => JsValue::unknown_if(
ignore,
JsValue::WellKnownFunction(WellKnownFunctionKind::WorkerConstructor),
true,
"ignored Worker constructor",
),
"define" => JsValue::WellKnownFunction(WellKnownFunctionKind::Define), "define" => JsValue::WellKnownFunction(WellKnownFunctionKind::Define),
"URL" => JsValue::WellKnownFunction(WellKnownFunctionKind::URLConstructor), "URL" => JsValue::WellKnownFunction(WellKnownFunctionKind::URLConstructor),
"Worker" => JsValue::WellKnownFunction(WellKnownFunctionKind::WorkerConstructor),
"process" => JsValue::WellKnownObject(WellKnownObjectKind::NodeProcess), "process" => JsValue::WellKnownObject(WellKnownObjectKind::NodeProcess),
"Object" => JsValue::WellKnownObject(WellKnownObjectKind::GlobalObject), "Object" => JsValue::WellKnownObject(WellKnownObjectKind::GlobalObject),
"Buffer" => JsValue::WellKnownObject(WellKnownObjectKind::NodeBuffer), "Buffer" => JsValue::WellKnownObject(WellKnownObjectKind::NodeBuffer),
...@@ -3976,6 +3997,7 @@ mod tests { ...@@ -3976,6 +3997,7 @@ mod tests {
linker::link, linker::link,
JsValue, JsValue,
}; };
use crate::analyzer::imports::ImportAttributes;
#[fixture("tests/analyzer/graph/**/input.js")] #[fixture("tests/analyzer/graph/**/input.js")]
fn fixture(input: PathBuf) { fn fixture(input: PathBuf) {
...@@ -4064,10 +4086,11 @@ mod tests { ...@@ -4064,10 +4086,11 @@ mod tests {
let start = Instant::now(); let start = Instant::now();
let mut resolved = Vec::new(); let mut resolved = Vec::new();
for (id, val) in named_values.iter() { for (id, val) in named_values.iter().cloned() {
let val = val.clone();
let start = Instant::now(); let start = Instant::now();
let res = resolve(&var_graph, val).await; // Ideally this would use eval_context.imports.get_attributes(span), but the
// span isn't available here
let res = resolve(&var_graph, val, ImportAttributes::empty_ref()).await;
let time = start.elapsed(); let time = start.elapsed();
if time.as_millis() > 1 { if time.as_millis() > 1 {
println!( println!(
...@@ -4077,7 +4100,7 @@ mod tests { ...@@ -4077,7 +4100,7 @@ mod tests {
); );
} }
resolved.push((id.clone(), res)); resolved.push((id, res));
} }
let time = start.elapsed(); let time = start.elapsed();
if time.as_millis() > 1 { if time.as_millis() > 1 {
...@@ -4124,10 +4147,16 @@ mod tests { ...@@ -4124,10 +4147,16 @@ mod tests {
for arg in args { for arg in args {
match arg { match arg {
EffectArg::Value(v) => { EffectArg::Value(v) => {
new_args.push(resolve(var_graph, v).await); new_args.push(
resolve(var_graph, v, ImportAttributes::empty_ref())
.await,
);
} }
EffectArg::Closure(v, effects) => { EffectArg::Closure(v, effects) => {
new_args.push(resolve(var_graph, v).await); new_args.push(
resolve(var_graph, v, ImportAttributes::empty_ref())
.await,
);
queue.extend( queue.extend(
effects.effects.into_iter().rev().map(|e| (i, e)), effects.effects.into_iter().rev().map(|e| (i, e)),
); );
...@@ -4143,7 +4172,9 @@ mod tests { ...@@ -4143,7 +4172,9 @@ mod tests {
Effect::Conditional { Effect::Conditional {
condition, kind, .. condition, kind, ..
} => { } => {
let condition = resolve(&var_graph, condition).await; let condition =
resolve(&var_graph, condition, ImportAttributes::empty_ref())
.await;
resolved.push((format!("{parent} -> {i} conditional"), condition)); resolved.push((format!("{parent} -> {i} conditional"), condition));
match *kind { match *kind {
ConditionalKind::If { then } => { ConditionalKind::If { then } => {
...@@ -4184,9 +4215,18 @@ mod tests { ...@@ -4184,9 +4215,18 @@ mod tests {
}; };
} }
Effect::Call { Effect::Call {
func, args, new, .. func,
args,
new,
span,
..
} => { } => {
let func = resolve(&var_graph, func).await; let func = resolve(
&var_graph,
func,
eval_context.imports.get_attributes(span),
)
.await;
let new_args = handle_args(args, &mut queue, &var_graph, i).await; let new_args = handle_args(args, &mut queue, &var_graph, i).await;
resolved.push(( resolved.push((
format!("{parent} -> {i} call"), format!("{parent} -> {i} call"),
...@@ -4201,7 +4241,8 @@ mod tests { ...@@ -4201,7 +4241,8 @@ mod tests {
resolved.push((format!("{parent} -> {i} free var"), var)); resolved.push((format!("{parent} -> {i} free var"), var));
} }
Effect::TypeOf { arg, .. } => { Effect::TypeOf { arg, .. } => {
let arg = resolve(&var_graph, arg).await; let arg =
resolve(&var_graph, arg, ImportAttributes::empty_ref()).await;
resolved.push(( resolved.push((
format!("{parent} -> {i} typeof"), format!("{parent} -> {i} typeof"),
JsValue::type_of(Box::new(arg)), JsValue::type_of(Box::new(arg)),
...@@ -4210,8 +4251,10 @@ mod tests { ...@@ -4210,8 +4251,10 @@ mod tests {
Effect::MemberCall { Effect::MemberCall {
obj, prop, args, .. obj, prop, args, ..
} => { } => {
let obj = resolve(&var_graph, obj).await; let obj =
let prop = resolve(&var_graph, prop).await; resolve(&var_graph, obj, ImportAttributes::empty_ref()).await;
let prop =
resolve(&var_graph, prop, ImportAttributes::empty_ref()).await;
let new_args = handle_args(args, &mut queue, &var_graph, i).await; let new_args = handle_args(args, &mut queue, &var_graph, i).await;
resolved.push(( resolved.push((
format!("{parent} -> {i} member call"), format!("{parent} -> {i} member call"),
...@@ -4268,7 +4311,7 @@ mod tests { ...@@ -4268,7 +4311,7 @@ mod tests {
.unwrap(); .unwrap();
} }
async fn resolve(var_graph: &VarGraph, val: JsValue) -> JsValue { async fn resolve(var_graph: &VarGraph, val: JsValue, attributes: &ImportAttributes) -> JsValue {
turbo_tasks_testing::VcStorage::with(async { turbo_tasks_testing::VcStorage::with(async {
let compile_time_info = CompileTimeInfo::builder(Environment::new(Value::new( let compile_time_info = CompileTimeInfo::builder(Environment::new(Value::new(
ExecutionEnvironment::NodeJsLambda( ExecutionEnvironment::NodeJsLambda(
...@@ -4290,7 +4333,13 @@ mod tests { ...@@ -4290,7 +4333,13 @@ mod tests {
var_graph, var_graph,
val, val,
&super::test_utils::early_visitor, &super::test_utils::early_visitor,
&(|val| Box::pin(super::test_utils::visitor(val, compile_time_info))), &(|val| {
Box::pin(super::test_utils::visitor(
val,
compile_time_info,
attributes,
))
}),
Default::default(), Default::default(),
) )
.await .await
......
...@@ -370,7 +370,7 @@ struct AnalysisState<'a> { ...@@ -370,7 +370,7 @@ struct AnalysisState<'a> {
impl<'a> AnalysisState<'a> { impl<'a> AnalysisState<'a> {
/// Links a value to the graph, returning the linked value. /// Links a value to the graph, returning the linked value.
async fn link_value(&self, value: JsValue, overrides: &ImportAttributes) -> Result<JsValue> { async fn link_value(&self, value: JsValue, attributes: &ImportAttributes) -> Result<JsValue> {
let fun_args_values = self.fun_args_values.lock().clone(); let fun_args_values = self.fun_args_values.lock().clone();
link( link(
self.var_graph, self.var_graph,
...@@ -382,7 +382,7 @@ impl<'a> AnalysisState<'a> { ...@@ -382,7 +382,7 @@ impl<'a> AnalysisState<'a> {
value, value,
self.compile_time_info, self.compile_time_info,
self.var_graph, self.var_graph,
overrides, attributes,
) )
}, },
fun_args_values, fun_args_values,
...@@ -2436,10 +2436,10 @@ async fn value_visitor( ...@@ -2436,10 +2436,10 @@ async fn value_visitor(
v: JsValue, v: JsValue,
compile_time_info: Vc<CompileTimeInfo>, compile_time_info: Vc<CompileTimeInfo>,
var_graph: &VarGraph, var_graph: &VarGraph,
overrides: &ImportAttributes, attributes: &ImportAttributes,
) -> Result<(JsValue, bool)> { ) -> Result<(JsValue, bool)> {
let (mut v, modified) = let (mut v, modified) =
value_visitor_inner(origin, v, compile_time_info, var_graph, overrides).await?; value_visitor_inner(origin, v, compile_time_info, var_graph, attributes).await?;
v.normalize_shallow(); v.normalize_shallow();
Ok((v, modified)) Ok((v, modified))
} }
...@@ -2449,9 +2449,9 @@ async fn value_visitor_inner( ...@@ -2449,9 +2449,9 @@ async fn value_visitor_inner(
v: JsValue, v: JsValue,
compile_time_info: Vc<CompileTimeInfo>, compile_time_info: Vc<CompileTimeInfo>,
var_graph: &VarGraph, var_graph: &VarGraph,
overrides: &ImportAttributes, attributes: &ImportAttributes,
) -> Result<(JsValue, bool)> { ) -> Result<(JsValue, bool)> {
let ImportAttributes { ignore, .. } = *overrides; let ImportAttributes { ignore, .. } = *attributes;
// This check is just an optimization // This check is just an optimization
if v.get_defineable_name_len().is_some() { if v.get_defineable_name_len().is_some() {
let compile_time_info = compile_time_info.await?; let compile_time_info = compile_time_info.await?;
......
...@@ -16,13 +16,16 @@ ...@@ -16,13 +16,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
0, 0,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -51,13 +54,16 @@ ...@@ -51,13 +54,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
1, 1,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -105,13 +111,16 @@ ...@@ -105,13 +111,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
1, 1,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -151,13 +160,16 @@ ...@@ -151,13 +160,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
2, 2,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -186,13 +198,16 @@ ...@@ -186,13 +198,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
3, 3,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -240,13 +255,16 @@ ...@@ -240,13 +255,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
3, 3,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -275,13 +293,16 @@ ...@@ -275,13 +293,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
4, 4,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -329,13 +350,16 @@ ...@@ -329,13 +350,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
4, 4,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -364,13 +388,16 @@ ...@@ -364,13 +388,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
5, 5,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -418,13 +445,16 @@ ...@@ -418,13 +445,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
5, 5,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -453,13 +483,16 @@ ...@@ -453,13 +483,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
6, 6,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -507,13 +540,16 @@ ...@@ -507,13 +540,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
6, 6,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -542,13 +578,16 @@ ...@@ -542,13 +578,16 @@
), ),
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
7, 7,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -596,13 +635,16 @@ ...@@ -596,13 +635,16 @@
], ],
ast_path: [ ast_path: [
Program( Program(
Script, Module,
), ),
Script( Module(
Body( Body(
7, 7,
), ),
), ),
ModuleItem(
Stmt,
),
Stmt( Stmt(
Decl, Decl,
), ),
...@@ -625,4 +667,105 @@ ...@@ -625,4 +667,105 @@
in_try: false, in_try: false,
new: false, new: false,
}, },
FreeVar {
var: FreeVar(
"require",
),
ast_path: [
Program(
Module,
),
Module(
Body(
8,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDecl,
),
ExportDecl(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
CallExpr(
Callee,
),
Callee(
Expr,
),
Expr(
Ident,
),
],
span: 476..483,
in_try: false,
},
Call {
func: FreeVar(
"require",
),
args: [
Value(
Constant(
Str(
Word(
"exported_t_r",
),
),
),
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
8,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDecl,
),
ExportDecl(
Decl,
),
Decl(
Var,
),
VarDecl(
Decls(
0,
),
),
VarDeclarator(
Init,
),
Expr(
Call,
),
],
span: 476..527,
in_try: false,
new: false,
},
] ]
exported_t_r = FreeVar(require)("exported_t_r")
t_i = FreeVar(import)("t_i") t_i = FreeVar(import)("t_i")
t_r = ( t_r = (
......
[ [
(
"exported_t_r",
Call(
3,
FreeVar(
"require",
),
[
Constant(
Str(
Word(
"exported_t_r",
),
),
),
],
),
),
( (
"t_i", "t_i",
Call( Call(
......
...@@ -6,3 +6,5 @@ const w_r = require(/* webpackIgnore: true */ 'w_r_t') ...@@ -6,3 +6,5 @@ const w_r = require(/* webpackIgnore: true */ 'w_r_t')
const w_r = require(/* webpackIgnore: false */ 'w_r_f') const w_r = require(/* webpackIgnore: false */ 'w_r_f')
const t_r = require(/* turbopackIgnore: true */ 't_r_t') const t_r = require(/* turbopackIgnore: true */ 't_r_t')
const t_r = require(/* turbopackIgnore: false */ 't_r_f') const t_r = require(/* turbopackIgnore: false */ 't_r_f')
export const exported_t_r = require(/* turbopackIgnore: true */ "exported_t_r")
0 -> 1 call = import*0*("w_i") 0 -> 1 call = ???*0*("w_i")
- *0* import: The dynamic import() method from the ESM specification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports - *0* import*1*
⚠️ ignored import
⚠️ This value might have side effects
- *1* import: The dynamic import() method from the ESM specification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports
0 -> 2 free var = FreeVar(require) 0 -> 2 free var = FreeVar(require)
0 -> 3 call = require*0*("w_i_f") 0 -> 3 call = require*0*("w_i_f")
- *0* require: The require method from CommonJS - *0* require: The require method from CommonJS
0 -> 4 call = import*0*("t_i") 0 -> 4 call = ???*0*("t_i")
- *0* import: The dynamic import() method from the ESM specification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports - *0* import*1*
⚠️ ignored import
⚠️ This value might have side effects
- *1* import: The dynamic import() method from the ESM specification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports
0 -> 5 free var = FreeVar(require) 0 -> 5 free var = FreeVar(require)
...@@ -16,8 +22,11 @@ ...@@ -16,8 +22,11 @@
0 -> 7 free var = FreeVar(require) 0 -> 7 free var = FreeVar(require)
0 -> 8 call = require*0*("w_r_t") 0 -> 8 call = ???*0*("w_r_t")
- *0* require: The require method from CommonJS - *0* require*1*
⚠️ ignored require
⚠️ This value might have side effects
- *1* require: The require method from CommonJS
0 -> 9 free var = FreeVar(require) 0 -> 9 free var = FreeVar(require)
...@@ -26,10 +35,21 @@ ...@@ -26,10 +35,21 @@
0 -> 11 free var = FreeVar(require) 0 -> 11 free var = FreeVar(require)
0 -> 12 call = require*0*("t_r_t") 0 -> 12 call = ???*0*("t_r_t")
- *0* require: The require method from CommonJS - *0* require*1*
⚠️ ignored require
⚠️ This value might have side effects
- *1* require: The require method from CommonJS
0 -> 13 free var = FreeVar(require) 0 -> 13 free var = FreeVar(require)
0 -> 14 call = require*0*("t_r_f") 0 -> 14 call = require*0*("t_r_f")
- *0* require: The require method from CommonJS - *0* require: The require method from CommonJS
0 -> 15 free var = FreeVar(require)
0 -> 16 call = ???*0*("exported_t_r")
- *0* require*1*
⚠️ ignored require
⚠️ This value might have side effects
- *1* require: The require method from CommonJS
exported_t_r = module<exported_t_r, {}>
t_i = module<"t_i", {}> t_i = module<"t_i", {}>
t_r = (module<w_i_f, {}> | module<t_i_f, {}> | module<t_r_t, {}> | module<t_r_f, {}>) t_r = (module<w_i_f, {}> | module<t_i_f, {}> | module<t_r_t, {}> | module<t_r_f, {}>)
......
...@@ -14,3 +14,7 @@ require(/* turbopackIgnore: true */ "./ignore.cjs"); ...@@ -14,3 +14,7 @@ require(/* turbopackIgnore: true */ "./ignore.cjs");
// and for workers // and for workers
new Worker(/* webpackIgnore: true */ "./ignore.mjs"); new Worker(/* webpackIgnore: true */ "./ignore.mjs");
new Worker(/* turbopackIgnore: true */ "./ignore.cjs"); new Worker(/* turbopackIgnore: true */ "./ignore.cjs");
export function foo(plugin) {
return require(/* turbopackIgnore: true */ plugin)
}
...@@ -20,10 +20,14 @@ __turbopack_export_value__(__turbopack_worker_blob_url__([ ...@@ -20,10 +20,14 @@ __turbopack_export_value__(__turbopack_worker_blob_url__([
"output/c5b29_tests_snapshot_imports_ignore-comments_input_vercel_cjs_75b6e3___092279.js" "output/c5b29_tests_snapshot_imports_ignore-comments_input_vercel_cjs_75b6e3___092279.js"
])); ]));
}}), }}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js [test] (ecmascript)": (function(__turbopack_context__) { "[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js [test] (ecmascript)": ((__turbopack_context__) => {
"use strict";
var { r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, b: __turbopack_worker_blob_url__, g: global, __dirname, m: module, e: exports, t: require } = __turbopack_context__; var { r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, b: __turbopack_worker_blob_url__, g: global, __dirname, z: require } = __turbopack_context__;
{ {
__turbopack_esm__({
"foo": (()=>foo)
});
const __TURBOPACK__import$2e$meta__ = { const __TURBOPACK__import$2e$meta__ = {
get url () { get url () {
return `file://${__turbopack_resolve_absolute_path__("turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js")}`; return `file://${__turbopack_resolve_absolute_path__("turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js")}`;
...@@ -42,6 +46,9 @@ require(/* turbopackIgnore: true */ "./ignore.cjs"); ...@@ -42,6 +46,9 @@ require(/* turbopackIgnore: true */ "./ignore.cjs");
// and for workers // and for workers
new Worker(/* webpackIgnore: true */ "./ignore.mjs"); new Worker(/* webpackIgnore: true */ "./ignore.mjs");
new Worker(/* turbopackIgnore: true */ "./ignore.cjs"); new Worker(/* turbopackIgnore: true */ "./ignore.cjs");
function foo(plugin) {
return require(/* turbopackIgnore: true */ plugin);
}
}}), }}),
}]); }]);
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
"sections": [ "sections": [
{"offset": {"line": 6, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/vercel.cjs"],"sourcesContent":["module.exports = \"turbopack\";\n"],"names":[],"mappings":"AAAA,OAAO,OAAO,GAAG"}}, {"offset": {"line": 6, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/vercel.cjs"],"sourcesContent":["module.exports = \"turbopack\";\n"],"names":[],"mappings":"AAAA,OAAO,OAAO,GAAG"}},
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, {"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}},
{"offset": {"line": 26, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js"],"sourcesContent":["import(\"./vercel.mjs\").then(console.log);\nimport(/* webpackIgnore: false */ \"./vercel.mjs\").then(console.log);\nconsole.log(require(\"./vercel.cjs\"));\nnew Worker(/* turbopackIgnore: false */ new URL(\"./vercel.cjs\", import.meta.url));\n\n// turbopack shouldn't attempt to bundle these, and they should be preserved in the output\nimport(/* webpackIgnore: true */ \"./ignore.mjs\");\nimport(/* turbopackIgnore: true */ \"./ignore.mjs\");\n\n// this should work for cjs requires too\nrequire(/* webpackIgnore: true */ \"./ignore.cjs\");\nrequire(/* turbopackIgnore: true */ \"./ignore.cjs\");\n\n// and for workers\nnew Worker(/* webpackIgnore: true */ \"./ignore.mjs\");\nnew Worker(/* turbopackIgnore: true */ \"./ignore.cjs\");\n"],"names":[],"mappings":";;;;;AAAA,oLAAuB,IAAI,CAAC,QAAQ,GAAG;AACvC,oLAAkD,IAAI,CAAC,QAAQ,GAAG;AAClE,QAAQ,GAAG;AACX,IAAI;AAEJ,0FAA0F;AAC1F,MAAM,CAAC,uBAAuB,GAAG;AACjC,MAAM,CAAC,yBAAyB,GAAG;AAEnC,wCAAwC;AACxC,QAAQ,uBAAuB,GAAG;AAClC,QAAQ,yBAAyB,GAAG;AAEpC,kBAAkB;AAClB,IAAI,OAAO,uBAAuB,GAAG;AACrC,IAAI,OAAO,yBAAyB,GAAG"}}, {"offset": {"line": 27, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js"],"sourcesContent":["import(\"./vercel.mjs\").then(console.log);\nimport(/* webpackIgnore: false */ \"./vercel.mjs\").then(console.log);\nconsole.log(require(\"./vercel.cjs\"));\nnew Worker(/* turbopackIgnore: false */ new URL(\"./vercel.cjs\", import.meta.url));\n\n// turbopack shouldn't attempt to bundle these, and they should be preserved in the output\nimport(/* webpackIgnore: true */ \"./ignore.mjs\");\nimport(/* turbopackIgnore: true */ \"./ignore.mjs\");\n\n// this should work for cjs requires too\nrequire(/* webpackIgnore: true */ \"./ignore.cjs\");\nrequire(/* turbopackIgnore: true */ \"./ignore.cjs\");\n\n// and for workers\nnew Worker(/* webpackIgnore: true */ \"./ignore.mjs\");\nnew Worker(/* turbopackIgnore: true */ \"./ignore.cjs\");\n\nexport function foo(plugin) {\n return require(/* turbopackIgnore: true */ plugin)\n}\n"],"names":[],"mappings":";;;;;;;;AAAA,oLAAuB,IAAI,CAAC,QAAQ,GAAG;AACvC,oLAAkD,IAAI,CAAC,QAAQ,GAAG;AAClE,QAAQ,GAAG;AACX,IAAI;AAEJ,0FAA0F;AAC1F,MAAM,CAAC,uBAAuB,GAAG;AACjC,MAAM,CAAC,yBAAyB,GAAG;AAEnC,wCAAwC;AACxC,QAAQ,uBAAuB,GAAG;AAClC,QAAQ,yBAAyB,GAAG;AAEpC,kBAAkB;AAClB,IAAI,OAAO,uBAAuB,GAAG;AACrC,IAAI,OAAO,yBAAyB,GAAG;AAEhC,SAAS,IAAI,MAAM;IACxB,OAAO,QAAQ,yBAAyB,GAAG;AAC7C"}},
{"offset": {"line": 44, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] {"offset": {"line": 51, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}]
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment