2020-07-03 21:39:25 +00:00
|
|
|
test("regular comments", () => {
|
2020-10-29 17:55:24 +00:00
|
|
|
const source = `
|
|
|
|
var i = 0;
|
2020-07-03 21:39:25 +00:00
|
|
|
// i++;
|
|
|
|
/* i++; */
|
|
|
|
/*
|
|
|
|
i++;
|
|
|
|
*/
|
2020-10-29 17:55:24 +00:00
|
|
|
/**/ i++;
|
2021-06-18 18:09:17 +00:00
|
|
|
i;`;
|
2020-04-13 17:50:58 +00:00
|
|
|
|
2020-10-29 17:55:24 +00:00
|
|
|
expect(source).toEvalTo(1);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-04-13 17:50:58 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
test("html comments", () => {
|
2020-10-29 17:55:24 +00:00
|
|
|
const source = `
|
|
|
|
var i = 0;
|
|
|
|
var j = 0;
|
2020-07-03 21:39:25 +00:00
|
|
|
<!-- i++; --> i++;
|
|
|
|
<!-- i++;
|
|
|
|
i++;
|
|
|
|
--> i++;
|
2020-10-29 17:55:24 +00:00
|
|
|
/**/ --> i++;
|
|
|
|
j --> i++;
|
2021-06-18 18:09:17 +00:00
|
|
|
i;`;
|
2020-10-29 17:55:24 +00:00
|
|
|
expect(source).toEvalTo(2);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-10-26 20:10:50 +00:00
|
|
|
|
2021-12-19 01:27:25 +00:00
|
|
|
test("html comments directly after block comment", () => {
|
|
|
|
expect("0 /* */-->i").not.toEval();
|
|
|
|
expect(`0 /*
|
|
|
|
*/-->i`).toEval();
|
|
|
|
expect(`0 /*
|
|
|
|
*/-->i
|
|
|
|
'a'`).toEvalTo("a");
|
|
|
|
});
|
|
|
|
|
2020-10-26 20:10:50 +00:00
|
|
|
test("unterminated multi-line comment", () => {
|
|
|
|
expect("/*").not.toEval();
|
|
|
|
expect("/**").not.toEval();
|
|
|
|
expect("/*/").not.toEval();
|
|
|
|
expect("/* foo").not.toEval();
|
|
|
|
expect("foo /*").not.toEval();
|
|
|
|
});
|
2021-06-18 18:11:26 +00:00
|
|
|
|
|
|
|
test("hashbang comments", () => {
|
|
|
|
expect("#!").toEvalTo(undefined);
|
|
|
|
expect("#!/bin/js").toEvalTo(undefined);
|
|
|
|
expect("#!\n1").toEvalTo(1);
|
|
|
|
expect(" #!").not.toEval();
|
|
|
|
expect("\n#!").not.toEval();
|
|
|
|
expect("#!\n#!").not.toEval();
|
|
|
|
});
|