ladybird/Userland/Libraries/LibJS/Tests/comments-basic.js
Linus Groh 597cf88c08 LibJS: Implement the 'Hashbang Grammar for JS' proposal
Stage 3 since August 2019 - we already have shebang stripping
implemented in js(1), so this removes it from there in favor of adding
support to the lexer directly.

Most straightforward proposal and implementation I've ever seen :^)

https://github.com/tc39/proposal-hashbang
2021-06-18 20:35:23 +01:00

44 lines
803 B
JavaScript

test("regular comments", () => {
const source = `
var i = 0;
// i++;
/* i++; */
/*
i++;
*/
/**/ i++;
i;`;
expect(source).toEvalTo(1);
});
test("html comments", () => {
const source = `
var i = 0;
var j = 0;
<!-- i++; --> i++;
<!-- i++;
i++;
--> i++;
/**/ --> i++;
j --> i++;
i;`;
expect(source).toEvalTo(2);
});
test("unterminated multi-line comment", () => {
expect("/*").not.toEval();
expect("/**").not.toEval();
expect("/*/").not.toEval();
expect("/* foo").not.toEval();
expect("foo /*").not.toEval();
});
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();
});