Skip to content

Commit 6f21750

Browse files
committed
TS: Review
1 parent ca79b08 commit 6f21750

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

javascript/extractor/lib/typescript/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ Debugging
1111

1212
To debug the parser script:
1313

14-
1. Launch an extraction process with the environment variable `SEMMLE_TYPESCRIPT_ATTACH_DEBUGGER`
15-
set to `break`.
14+
1. Launch an extraction process with the environment variable `SEMMLE_TYPESCRIPT_NODE_FLAGS`
15+
set to `--inspect`, or `--inspect-brk` if you wish to pause on entry.
1616

1717
2. Open VSCode and choose "Debug: Attach to Node process" from the command palette, and
1818
choose the process that looks like the parser-wrapper.
19-
20-
If you don't wish to pause on entry, instead set `SEMMLE_TYPESCRIPT_ATTACH_DEBUGGER` to
21-
any non-empty value.

javascript/extractor/src/com/semmle/js/parser/TypeScriptParser.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,19 @@ public class TypeScriptParser {
9999
public static final String TYPESCRIPT_RAM_RESERVE_SUFFIX = "TYPESCRIPT_RAM_RESERVE";
100100

101101
/**
102-
* An environment variable which, if set, allows a debugger to be attached to the Node.js
103-
* process. Remote debugging will not be enabled.
102+
* An environment variable with additional VM arguments to pass to the Node process.
104103
* <p>
105-
* If set to <code>break</code> the Node.js process will pause on entry waiting for the
106-
* debugger to attach (<code>--inspect-brk</code>). If set to any other non-empty value,
107-
* it will just enable debugging (<code>--inspect</code>).
104+
* Only <code>--inspect</code> or <code>--inspect-brk</code> may be used at the moment.
108105
*/
109-
public static final String TYPESCRIPT_ATTACH_DEBUGGER = "SEMMLE_TYPESCRIPT_ATTACH_DEBUGGER";
106+
public static final String TYPESCRIPT_NODE_FLAGS = "SEMMLE_TYPESCRIPT_NODE_FLAGS";
107+
108+
/**
109+
* Flags that may be passed using {@link #TYPESCRIPT_NODE_FLAGS}
110+
*/
111+
private static final Set<String> allowedDebugNodeFlags = new HashSet<String>(Arrays.fromList(
112+
"--inspect",
113+
"--inspect-brk"
114+
));
110115

111116
/** The Node.js parser wrapper process, if it has been started already. */
112117
private Process parserWrapperProcess;
@@ -213,9 +218,7 @@ private List<String> getNodeJsRuntimeInvocation(String ...args) {
213218
result.add(nodeJsRuntime);
214219
result.addAll(nodeJsRuntimeExtraArgs);
215220
for(String arg : args) {
216-
if (arg.length() > 0) {
217-
result.add(arg);
218-
}
221+
result.add(arg);
219222
}
220223
return result;
221224
}
@@ -249,21 +252,15 @@ private void setupParserWrapper() {
249252

250253
File parserWrapper = getParserWrapper();
251254

252-
String debuggerFlag = Env.systemEnv().get(TYPESCRIPT_ATTACH_DEBUGGER);
253-
String inspectArg = "";
254-
if (debuggerFlag != null && debuggerFlag.length() > 0) {
255-
if (debuggerFlag.equalsIgnoreCase("break")) {
256-
inspectArg = "--inspect-brk";
257-
} else {
258-
inspectArg = "--inspect";
259-
}
260-
}
255+
String debugFlagString = Env.systemEnv().getNonEmpty(TYPESCRIPT_NODE_FLAGS);
256+
List<String> debugFlags = debugFlagString == null ? new ArrayList<>() : debugFlagString.split(" ");
257+
debugFlags.retainAll(allowedDebugNodeFlags);
258+
259+
List<String> cmd = getNodeJsRuntimeInvocation();
260+
cmd.add("--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb));
261+
cmd.addAll(debugFlags);
262+
cmd.add(parserWrapper.getAbsolutePath());
261263

262-
List<String> cmd = getNodeJsRuntimeInvocation(
263-
"--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb),
264-
inspectArg,
265-
parserWrapper.getAbsolutePath()
266-
);
267264
ProcessBuilder pb = new ProcessBuilder(cmd);
268265
parserWrapperCommand = StringUtil.glue(" ", cmd);
269266
pb.environment().put("SEMMLE_TYPESCRIPT_MEMORY_THRESHOLD", "" + mainMemoryMb);

0 commit comments

Comments
 (0)