Skip to content

Commit

Permalink
[[FIX]] Limit positions for class declarations
Browse files Browse the repository at this point in the history
JSHint already includes logic to disallow `let` and `const` declarations
in certain statement positions. Extend the definition of `class` tokens
so that it applies the same restrictions to class declarations.
  • Loading branch information
jugglinmike authored and rwaldron committed Jun 16, 2020
1 parent c45d1b2 commit 0f0acd8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2743,8 +2743,7 @@ var JSHINT = (function() {
state.syntax["new"].exps = true;


// Class statement
blockstmt("class", function(context) {
var classDeclaration = blockstmt("class", function(context) {
var className, classNameToken;
var inexport = context & prodParams.export;

Expand Down Expand Up @@ -2782,7 +2781,9 @@ var JSHINT = (function() {
state.funct["(scope)"].stack();
classBody(this, context);
return this;
}).exps = true;
});
classDeclaration.exps = true;
classDeclaration.declaration = true;

/*
Class expression
Expand Down
19 changes: 0 additions & 19 deletions tests/test262/expectations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,12 @@ test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-inv
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters-expression-body.js(strict mode)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters.js(default)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters.js(strict mode)
test/language/statements/do-while/decl-cls.js(default)
test/language/statements/do-while/decl-cls.js(strict mode)
test/language/statements/for-in/decl-cls.js(default)
test/language/statements/for-in/decl-cls.js(strict mode)
test/language/statements/for-in/head-const-bound-names-fordecl-tdz.js(default)
test/language/statements/for-in/head-const-bound-names-fordecl-tdz.js(strict mode)
test/language/statements/for-in/head-let-bound-names-fordecl-tdz.js(default)
test/language/statements/for-in/head-let-bound-names-fordecl-tdz.js(strict mode)
test/language/statements/for-in/head-lhs-let.js(default)
test/language/statements/for/decl-cls.js(default)
test/language/statements/for/decl-cls.js(strict mode)
test/language/statements/for/head-lhs-let.js(default)
test/language/statements/if/if-cls-else-cls.js(default)
test/language/statements/if/if-cls-else-cls.js(strict mode)
test/language/statements/if/if-cls-else-stmt.js(default)
test/language/statements/if/if-cls-else-stmt.js(strict mode)
test/language/statements/if/if-cls-no-else.js(default)
test/language/statements/if/if-cls-no-else.js(strict mode)
test/language/statements/if/if-decl-else-decl-strict.js(strict mode)
test/language/statements/if/if-decl-else-stmt-strict.js(strict mode)
test/language/statements/if/if-decl-no-else-strict.js(strict mode)
Expand All @@ -237,8 +225,6 @@ test/language/statements/if/if-gen-else-stmt.js(default)
test/language/statements/if/if-gen-else-stmt.js(strict mode)
test/language/statements/if/if-gen-no-else.js(default)
test/language/statements/if/if-gen-no-else.js(strict mode)
test/language/statements/if/if-stmt-else-cls.js(default)
test/language/statements/if/if-stmt-else-cls.js(strict mode)
test/language/statements/if/if-stmt-else-decl-strict.js(strict mode)
test/language/statements/if/if-stmt-else-fun-strict.js(strict mode)
test/language/statements/if/if-stmt-else-gen.js(default)
Expand Down Expand Up @@ -279,21 +265,16 @@ test/language/statements/return/S12.9_A1_T8.js(default)
test/language/statements/return/S12.9_A1_T8.js(strict mode)
test/language/statements/return/S12.9_A1_T9.js(default)
test/language/statements/return/S12.9_A1_T9.js(strict mode)
test/language/statements/for-of/decl-cls.js(default)
test/language/statements/for-of/decl-cls.js(strict mode)
test/language/statements/for-of/head-const-bound-names-fordecl-tdz.js(default)
test/language/statements/for-of/head-const-bound-names-fordecl-tdz.js(strict mode)
test/language/statements/for-of/head-let-bound-names-fordecl-tdz.js(default)
test/language/statements/for-of/head-let-bound-names-fordecl-tdz.js(strict mode)
test/language/statements/switch/S12.11_A2_T1.js(default)
test/language/statements/switch/S12.11_A2_T1.js(strict mode)
test/language/statements/while/decl-cls.js(default)
test/language/statements/while/decl-cls.js(strict mode)
test/language/statements/try/early-catch-duplicates.js(default)
test/language/statements/try/early-catch-duplicates.js(strict mode)
test/language/statements/try/early-catch-lex.js(default)
test/language/statements/try/early-catch-lex.js(strict mode)
test/language/statements/with/decl-cls.js(default)
test/language/statements/const/block-local-use-before-initialization-in-declaration-statement.js(default)
test/language/statements/const/block-local-use-before-initialization-in-declaration-statement.js(strict mode)
test/language/statements/const/block-local-use-before-initialization-in-prior-statement.js(default)
Expand Down

0 comments on commit 0f0acd8

Please sign in to comment.