Skip to content

Commit

Permalink
Add test for using both string a variable references to a CSS class n…
Browse files Browse the repository at this point in the history
…ame.

PiperOrigin-RevId: 544420853
  • Loading branch information
Closure Team authored and copybara-github committed Jun 29, 2023
1 parent 0102544 commit 04e0922
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/com/google/javascript/jscomp/ReplaceCssNamesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,58 @@ public void testVariableReferencesToCssClasses() {
assertThat(cssNames).containsExactly("fooStylesBar", 1);
}

@Test
public void testMixedVariableAndStringReferences() {
SourceFile cssVarsDefinition =
SourceFile.fromCode(
"foo/styles.css.closure.js",
lines(
"/**",
" * @fileoverview generated from foo/styles.css",
" * @sassGeneratedCssTs",
" */",
"goog.module('foo.styles$2ecss');",
"/** @type {{Bar: string, Baz: string}} */",
"exports.classes = {",
" 'Bar': goog.getCssName('fooStylesBar'),",
" 'Baz': goog.getCssName('fooStylesBaz'),",
"}"));
SourceFile cssVarsExpected =
SourceFile.fromCode(
"foo/styles.css.closure.js",
lines(
"/**",
" * @fileoverview generated from foo/styles.css",
" * @sassGeneratedCssTs",
" */",
"goog.module('foo.styles$2ecss');",
"/** @type {{Bar: string, Baz: string}} */",
"exports.classes = {",
" 'Bar': 'fsr',",
" 'Baz': 'fsz',",
"}"));
SourceFile importer =
SourceFile.fromCode(
"foo/importer.closure.js",
lines(
"goog.module('foo.importer');",
"/** @type {string} */",
"const foo_styles_css = goog.require('foo.styles$2ecss');",
"var x = foo_styles_css.classes.Bar;",
"var y = goog.getCssName('active');"));
SourceFile importerExpected =
SourceFile.fromCode(
"foo/importer.closure.js",
lines(
"goog.module('foo.importer');",
"/** @type {string} */",
"const foo_styles_css = goog.require('foo.styles$2ecss');",
"var x = foo_styles_css.classes.Bar;",
"var y = 'a';"));
test(srcs(cssVarsDefinition, importer), expected(cssVarsExpected, importerExpected));
assertThat(cssNames).containsExactly("fooStylesBar", 1, "active", 1);
}

@Test
public void testIgnoreReferencesInCssTsFiles() {
SourceFile cssVarsDefinition =
Expand Down

0 comments on commit 04e0922

Please sign in to comment.