-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
897a67e
commit 72d4abc
Showing
9 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/fixtures/parser/selector-parsing/simple-css-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script> | ||
let a = 10 | ||
</script> | ||
|
||
<span class="myClass">Hello!</span> | ||
|
||
<b>{a}</b> | ||
|
||
<style> | ||
.myClass { | ||
color: red; | ||
} | ||
b { | ||
font-size: xx-large; | ||
} | ||
a:active, | ||
a::before, | ||
b + a, | ||
b + .myClass, | ||
a[data-key="value"] { | ||
color: blue; | ||
} | ||
</style> |
Empty file.
20 changes: 20 additions & 0 deletions
20
tests/fixtures/parser/selector-parsing/simple-postcss-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="container"> | ||
<div class="div-class">Hello</div> | ||
|
||
<span class="span-class">World!</span> | ||
</div> | ||
|
||
<style lang="postcss"> | ||
body { | ||
colour: white; | ||
background-colour: grey; | ||
} | ||
a:active, | ||
a::before, | ||
b + a, | ||
b + .myClass, | ||
a[data-key="value"] { | ||
color: blue; | ||
} | ||
</style> |
Empty file.
26 changes: 26 additions & 0 deletions
26
tests/fixtures/parser/selector-parsing/simple-scss-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="container"> | ||
<div class="div-class">Hello</div> | ||
|
||
<span class="span-class">World!</span> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.container { | ||
.div-class { | ||
// This is an inline comment | ||
color: red; | ||
} | ||
.span-class { | ||
font-weight: bold; | ||
} | ||
a:active, | ||
a::before, | ||
b + a, | ||
b + .myClass, | ||
a[data-key="value"] { | ||
color: blue; | ||
} | ||
} | ||
</style> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import assert from "assert"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import type { Node } from "postcss"; | ||
import type { Root as SelectorRoot } from "postcss-selector-parser"; | ||
|
||
import { parseForESLint } from "../../../src/index.js"; | ||
import { | ||
generateParserOptions, | ||
listupFixtures, | ||
selectorNodeToJson, | ||
} from "./test-utils.js"; | ||
|
||
const dirname = path.dirname(new URL(import.meta.url).pathname); | ||
const SELECTOR_PARSING_FIXTURE_ROOT = path.resolve( | ||
dirname, | ||
"../../fixtures/parser/selector-parsing", | ||
); | ||
|
||
function parse(code: string, filePath: string, config: any) { | ||
return parseForESLint(code, generateParserOptions({ filePath }, config)); | ||
} | ||
|
||
describe("Check for AST.", () => { | ||
for (const { | ||
input, | ||
inputFileName, | ||
outputFileName, | ||
config, | ||
meetRequirements, | ||
} of listupFixtures(SELECTOR_PARSING_FIXTURE_ROOT)) { | ||
if (!meetRequirements("parse")) { | ||
continue; | ||
} | ||
describe(inputFileName, () => { | ||
let services: any; | ||
|
||
it("most to generate the expected selector AST.", () => { | ||
services = parse(input, inputFileName, config).services; | ||
if (!meetRequirements("test")) { | ||
return; | ||
} | ||
const styleContext = services.getStyleContext(); | ||
assert.strictEqual(styleContext.status, "success"); | ||
const selectorASTs: SelectorRoot[] = []; | ||
styleContext.sourceAst.walk((node: Node) => { | ||
if (node.type === "rule") { | ||
selectorASTs.push(services.getStyleSelectorAST(node)); | ||
} | ||
}); | ||
const output = fs.readFileSync(outputFileName, "utf8"); | ||
assert.strictEqual(`${selectorASTs.map(selectorNodeToJson)}\n`, output); | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters