Prechádzať zdrojové kódy

Make sure case statements are not treated as a single-statement context. Fixes #456.

Dmitry Panov 2 rokov pred
rodič
commit
d4bf6fde1b
2 zmenil súbory, kde vykonal 13 pridanie a 0 odobranie
  1. 12 0
      compiler_test.go
  2. 1 0
      parser/statement.go

+ 12 - 0
compiler_test.go

@@ -5601,6 +5601,18 @@ func TestForInLoopContinueOuter(t *testing.T) {
 	testScript(SCRIPT, _undefined, t)
 }
 
+func TestLexicalDeclInSwitch(t *testing.T) {
+	const SCRIPT = `
+	switch(0) {
+	    case 1:
+	        if (false) b = 3;
+	    case 2:
+	        const c = 1;
+	}
+	`
+	testScript(SCRIPT, _undefined, t)
+}
+
 /*
 func TestBabel(t *testing.T) {
 	src, err := os.ReadFile("babel7.js")

+ 1 - 0
parser/statement.go

@@ -488,6 +488,7 @@ func (self *_parser) parseCaseStatement() *ast.CaseStatement {
 			self.token == token.DEFAULT {
 			break
 		}
+		self.scope.allowLet = true
 		node.Consequent = append(node.Consequent, self.parseStatement())
 
 	}