mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +00:00 
			
		
		
		
	 597cf88c08
			
		
	
	
		597cf88c08
		
	
	
	
	
		
			
			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
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			803 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			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();
 | |
| });
 |