Skip to content

Commit

Permalink
add doc for require() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZank committed Aug 10, 2024
1 parent 2d1b7ee commit 8cc40b7
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/main/java/zzzank/probejs/docs/LoadClassFn.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,40 @@ public class LoadClassFn extends ProbeJSPlugin {

@Override
public void addGlobals(ScriptDump scriptDump) {
val fn = Statements
val javaFn = Statements
.func("java")
.param("className", Types.STRING)
.returnType(Types.ANY)
.build();

fn.addComment(
"@deprecated",
"Please use `require(...)` instead." ,
"Or just type `$`, and let auto-import call `require()` for you"
javaFn.addComment(
"@deprecated Please use `require(...)` instead.",
"" ,
"Or just type `$`, and let auto-import call `require()` for you",
"@see require"
);

scriptDump.addGlobal("java", fn);
val requireFn = Statements
.func("require")
.param("name", Types.STRING)
.returnType(Types.ANY)
.build();

requireFn.addComment(
"provided by ProbeJS, to support CommonJS style import/export",
"",
"You may have already noticed, classes dumped by ProbeJS have `packages/` before their TS module name.",
"This is used for differentiating internal classes and variables exported by users.",
"",
"For `require(\"packages/abcdefg\")` style call, where parameter string starts with `packages/`, ProbeJS",
"will try to locate corresponding java class, return located java class, or `undefined` if parameter",
"does not match any java class or located Java class is forbidden by KubeJS/Rhino",
"",
"For `require(\"./abcdefg\")` style call, where parameter string does NOT start with `packages/`, this",
"function call will be trimmed before being called. This is used for `export` support."
);

scriptDump.addGlobal("java", javaFn, requireFn);
}

@Override
Expand Down

0 comments on commit 8cc40b7

Please sign in to comment.