Skip to content

Commit 2f6d5fa

Browse files
committed
don't try to correct CSS variables to properties
1 parent 5859f8c commit 2f6d5fa

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

internal/css_ast/css_decl_table.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package css_ast
22

3-
import "github.com/evanw/esbuild/internal/helpers"
3+
import (
4+
"strings"
5+
6+
"github.com/evanw/esbuild/internal/helpers"
7+
)
48

59
type D uint16
610

@@ -646,6 +650,10 @@ var KnownDeclarations = map[string]D{
646650
var typoDetector *helpers.TypoDetector
647651

648652
func MaybeCorrectDeclarationTypo(text string) (string, bool) {
653+
if strings.HasPrefix(text, "--") {
654+
// Ignore CSS variables, which should not be corrected to CSS properties
655+
return "", false
656+
}
649657
if typoDetector == nil {
650658
// Lazily-initialize the typo detector for speed when it's not needed
651659
valid := make([]string, 0, len(KnownDeclarations))

internal/css_parser/css_parser_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,3 +1676,14 @@ func TestWarningUnexpectedCloseBrace(t *testing.T) {
16761676
}
16771677
`)
16781678
}
1679+
1680+
func TestPropertyTypoWarning(t *testing.T) {
1681+
expectParseError(t, "a { z-idnex: 0 }", "<stdin>: WARNING: \"z-idnex\" is not a known CSS property\nNOTE: Did you mean \"z-index\" instead?\n")
1682+
expectParseError(t, "a { x-index: 0 }", "<stdin>: WARNING: \"x-index\" is not a known CSS property\nNOTE: Did you mean \"z-index\" instead?\n")
1683+
1684+
// CSS variables should not be corrected
1685+
expectParseError(t, "a { --index: 0 }", "")
1686+
1687+
// Short names should not be corrected ("alt" is actually valid in WebKit, and should not become "all")
1688+
expectParseError(t, "a { alt: \"\" }", "")
1689+
}

internal/helpers/typos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func MakeTypoDetector(valid []string) TypoDetector {
1111

1212
// Add all combinations of each valid word with one character missing
1313
for _, correct := range valid {
14-
if len(correct) > 2 {
14+
if len(correct) > 3 {
1515
for i, ch := range correct {
1616
detector.oneCharTypos[correct[:i]+correct[i+utf8.RuneLen(ch):]] = correct
1717
}

0 commit comments

Comments
 (0)