0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00
This commit is contained in:
Marvin Hagemeister 2024-12-10 04:33:33 +01:00
parent 19baadf319
commit 280d10e801
20 changed files with 2218 additions and 1284 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -74,9 +74,9 @@ impl PluginRunner {
let (tx_req, rx_req) = channel(10); let (tx_req, rx_req) = channel(10);
let (tx_res, rx_res) = channel(10); let (tx_res, rx_res) = channel(10);
log::info!("spawning thread"); log::debug!("spawning thread");
let join_handle = std::thread::spawn(move || { let join_handle = std::thread::spawn(move || {
log::info!("PluginRunner thread spawned"); log::debug!("PluginRunner thread spawned");
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let fut = async move { let fut = async move {
let mut flags = Flags::default(); let mut flags = Flags::default();
@ -110,7 +110,7 @@ impl PluginRunner {
let mut worker = worker.into_main_worker(); let mut worker = worker.into_main_worker();
let runtime = &mut worker.js_runtime; let runtime = &mut worker.js_runtime;
log::info!("before loaded"); log::debug!("before loaded");
let obj_result = runtime.lazy_load_es_module_with_code( let obj_result = runtime.lazy_load_es_module_with_code(
"ext:cli/lint.js", "ext:cli/lint.js",
@ -125,7 +125,7 @@ impl PluginRunner {
} }
}; };
log::info!("After plugin loaded, capturing exports"); log::debug!("After plugin loaded, capturing exports");
let (install_plugin_fn, run_plugins_for_file_fn) = { let (install_plugin_fn, run_plugins_for_file_fn) = {
let scope = &mut runtime.handle_scope(); let scope = &mut runtime.handle_scope();
let module_exports: v8::Local<v8::Object> = let module_exports: v8::Local<v8::Object> =
@ -163,9 +163,9 @@ impl PluginRunner {
rx: rx_req, rx: rx_req,
}; };
// TODO(bartlomieju): send "host ready" message to the proxy // TODO(bartlomieju): send "host ready" message to the proxy
log::info!("running host loop"); log::debug!("running host loop");
runner.run_loop().await?; runner.run_loop().await?;
log::info!( log::debug!(
"PluginRunner thread finished, took {:?}", "PluginRunner thread finished, took {:?}",
std::time::Instant::now() - start std::time::Instant::now() - start
); );
@ -175,7 +175,7 @@ impl PluginRunner {
tokio_util::create_and_run_current_thread(fut) tokio_util::create_and_run_current_thread(fut)
}); });
log::info!("is thread finished {}", join_handle.is_finished()); log::debug!("is thread finished {}", join_handle.is_finished());
let proxy = PluginRunnerProxy { let proxy = PluginRunnerProxy {
tx: tx_req, tx: tx_req,
rx: Arc::new(tokio::sync::Mutex::new(rx_res)), rx: Arc::new(tokio::sync::Mutex::new(rx_res)),
@ -335,7 +335,7 @@ impl PluginRunnerProxy {
.send(PluginRunnerRequest::LoadPlugins(plugin_specifiers)) .send(PluginRunnerRequest::LoadPlugins(plugin_specifiers))
.await?; .await?;
let mut rx = self.rx.lock().await; let mut rx = self.rx.lock().await;
log::info!("receiving load plugins"); log::debug!("receiving load plugins");
if let Some(val) = rx.recv().await { if let Some(val) = rx.recv().await {
let PluginRunnerResponse::LoadPlugin(result) = val else { let PluginRunnerResponse::LoadPlugin(result) = val else {
unreachable!() unreachable!()

View file

@ -6394,6 +6394,11 @@ declare namespace Deno {
expressions: Expression[]; expressions: Expression[];
} }
export interface ParenthesisExpression extends BaseNode {
type: "ParenthesisExpression";
expression: Expression;
}
export interface Super extends BaseNode { export interface Super extends BaseNode {
type: "Super"; type: "Super";
} }
@ -6472,6 +6477,7 @@ declare namespace Deno {
| MetaProperty | MetaProperty
| NewExpression | NewExpression
| ObjectExpression | ObjectExpression
| ParenthesisExpression
| StaticBlock | StaticBlock
| SequenceExpression | SequenceExpression
| Super | Super
@ -7026,7 +7032,8 @@ declare namespace Deno {
TemplateLiteral?(node: TemplateLiteral): void; TemplateLiteral?(node: TemplateLiteral): void;
// Literals // Literals
BooleanLiteral?(node: BooleanLiteral): void; BooleanLiteral?(node: BigIntLiteral): void;
BigIntLiteral?(node: BooleanLiteral): void;
NullLiteral?(node: NullLiteral): void; NullLiteral?(node: NullLiteral): void;
NumericLiteral?(node: NumericLiteral): void; NumericLiteral?(node: NumericLiteral): void;
RegExpLiteral?(node: RegExpLiteral): void; RegExpLiteral?(node: RegExpLiteral): void;

View file

@ -1,7 +0,0 @@
{
"lint": {
"plugins": [
"./plugin.ts"
]
}
}

0
lint.md Normal file
View file

View file

@ -0,0 +1,24 @@
{
"tests": {
"program": {
"cwd": "./program",
"args": "lint --plugins=./plugin.ts source.ts",
"output": "program/log.out"
},
"statements": {
"cwd": "./statements",
"args": "lint --config=./statements/deno.json source.ts",
"output": "statement/log.out"
},
"expressions": {
"cwd": "./expressions",
"args": "lint --plugins=./plugin.ts source.ts",
"output": "expressions/log.out"
},
"literals": {
"cwd": "./literals",
"args": "lint --plugins=./plugin.ts source.ts",
"output": "literals/log.out"
}
}
}

View file

@ -0,0 +1,27 @@
CallExpression {
type: "CallExpression",
range: [ 9, 14 ],
optional: false
}
CallExpression {
type: "CallExpression",
range: [ 16, 25 ],
optional: false
}
CallExpression {
type: "CallExpression",
range: [ 27, 41 ],
optional: false
}
MemberExpression {
type: "MemberExpression",
range: [ 83, 86 ],
optional: false,
computed: false
}
MemberExpression {
type: "MemberExpression",
range: [ 88, 94 ],
optional: false,
computed: true
}

View file

@ -0,0 +1,17 @@
export default {
name: "ast_plugin",
rules: {
ast: {
create() {
return {
CallExpression(node) {
console.log(node);
},
MemberExpression(node) {
console.log(node);
},
};
},
},
},
} satisfies Deno.LintPlugin;

View file

@ -0,0 +1,9 @@
// Call
foo();
foo(1, 2);
foo(1, ...bar);
// FIXME foo?.(1);
// MemberExpression
a.b;
a["b"];

View file

@ -0,0 +1,44 @@
StringLiteral {
type: "StringLiteral",
range: [ 1, 8 ],
value: "foo\n"
}
StringLiteral {
type: "StringLiteral",
range: [ 10, 16 ],
value: 'bar"'
}
NumericLiteral { type: "NumericLiteral", range: [ 18, 19 ], value: 2 }
NumericLiteral {
type: "NumericLiteral",
range: [ 21, 24 ],
value: 2.3
}
NumericLiteral { type: "NumericLiteral", range: [ 26, 31 ], value: 0 }
BooleanLiteral {
type: "BooleanLiteral",
range: [ 33, 37 ],
value: true
}
BooleanLiteral {
type: "BooleanLiteral",
range: [ 39, 44 ],
value: false
}
NullLiteral { type: "NullLiteral", range: [ 46, 50 ], value: null }
RegExpLiteral {
type: "RegExpLiteral",
range: [ 52, 56 ],
pattern: "a",
flags: "g"
}
RegExpLiteral {
type: "RegExpLiteral",
range: [ 58, 65 ],
pattern: "[/g]",
flags: "m"
}
BigIntLiteral { type: "BigIntLiteral", range: [ 67, 69 ], value: 1n }
ArrayExpression { type: "ArrayExpression", range: [ 82, 91 ] }
ArrayExpression { type: "ArrayExpression", range: [ 93, 104 ] }
ArrayExpression { type: "ArrayExpression", range: [ 106, 114 ] }

View file

@ -0,0 +1,35 @@
export default {
name: "ast_plugin",
rules: {
ast: {
create() {
return {
ArrayExpression(node) {
console.log(node);
},
BooleanLiteral(node) {
console.log(node);
},
BigIntLiteral(node) {
console.log(node);
},
NullLiteral(node) {
console.log(node);
},
NumericLiteral(node) {
console.log(node);
},
ObjectExpression(node) {
console.log(node);
},
RegExpLiteral(node) {
console.log(node);
},
StringLiteral(node) {
console.log(node);
},
};
},
},
},
} satisfies Deno.LintPlugin;

View file

@ -0,0 +1,30 @@
"foo\n";
'bar"';
2;
2.3;
0b000;
true;
false;
null;
/a/g;
/[/g]/m;
1n;
// arrays
[1, 2, 3];
[1, ...foo];
[1, , 3];
// objects
a = {};
a = { foo };
a = { foo: 1 };
a = { ["foo\n"]: 1, 1: 2, "baz": 3 };
a = {
get foo() {
return 1;
},
set foo(a) {
2;
},
};

View file

@ -0,0 +1 @@
Program { type: "Program", range: [ 1, 1 ], sourceType: "script" }

View file

@ -0,0 +1,14 @@
export default {
name: "ast_plugin",
rules: {
ast: {
create() {
return {
Program(node) {
console.log(node);
},
};
},
},
},
} satisfies Deno.LintPlugin;

View file

@ -0,0 +1,8 @@
{
"lint": {
"plugins": ["./plugin.ts"],
"rules": {
"exclude": ["no-debugger"]
}
}
}

View file

@ -0,0 +1,2 @@
BreakStatement { type: "BreakStatement", range: [ 19, 25 ] }
BreakStatement { type: "BreakStatement", range: [ 54, 66 ] }

View file

@ -0,0 +1,20 @@
export default {
name: "ast_plugin",
rules: {
ast: {
create() {
return {
BreakStatement(node) {
console.log(node);
},
ContinueStatement(node) {
console.log(node);
},
ReturnStatement(node) {
console.log(node);
},
};
},
},
},
} satisfies Deno.LintPlugin;

View file

@ -0,0 +1,28 @@
// Break
while (false) {
break;
}
outer: while (false) {
break outer;
}
// Continue
while (false) {
continue;
}
outer: while (false) {
continue outer;
}
// Debugger
debugger;
// Return
(() => {
return;
});
(() => {
return 1;
});