-
-
Notifications
You must be signed in to change notification settings - Fork 24
Added style AST to SvelteStyleElement #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
024f9e9
Added PostCSS AST to SvelteStyleElement
marekdedic 93ef53d
Passing file name to PostCSS parser
marekdedic 0e13130
Added support for SCSS parsing
marekdedic c105390
Not parsing SASS syntax using SCSS parser
marekdedic 8d8b70e
Emiting a warning on unknown <style> language
marekdedic 51bec0c
Converting PostCSS AST to ESLint AST: adding the range property
marekdedic 1e612f5
Exporting <style> contents as ESLintCompatiblePostCSSNode
marekdedic b2c30a4
Renaming all PostCSS node types to prevent confusion with exisiting N…
marekdedic 414c85a
Removed unneeded type assertion
marekdedic 4fe0c9a
Converting PostCSS AST to ESLint AST: adding the loc property
marekdedic 572248c
Fixed lint issues by adding type assertions and checks
marekdedic cc8f48f
Removing file location from PostCSS AST
marekdedic f4d802e
Updated test fixtures
marekdedic 98319a6
Simplified ESLintCompatiblePostCSSNode so that type inference actuall…
marekdedic 5aa2f2b
Adding parent to PostCSS root
marekdedic 1db5f7d
Fixed ESLintCompatiblePostCSSNode for Container subclasses
marekdedic 9cfc436
Fixed type inference on the ESLintCompatiblePostCSSNode type
marekdedic 20aa0c5
Re-implemented PostCSS container
marekdedic 7a9fe6e
Removed default generic value from ESLintCompatiblePostCSSNode
marekdedic dc08b51
Fixed type discrimination
marekdedic 832cbdc
Fixed Root.parent type
marekdedic 2bf2125
Removed uneeded re-implementation of postcss Container
marekdedic 003418f
Fixed Container.walk() callback type
marekdedic acd0d56
Overriden the rest of Container properties
marekdedic ab5b55e
Merge branch 'main' into postcss-style-parsing
marekdedic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,125 @@ | ||
import type { | ||
AtRule, | ||
ChildNode, | ||
ChildProps, | ||
Comment, | ||
Container, | ||
Declaration, | ||
Node, | ||
Root, | ||
Rule, | ||
} from "postcss"; | ||
import type { Locations } from "./common"; | ||
import type { SvelteStyleElement } from "./html"; | ||
|
||
type RedefinedProperties = | ||
| "type" // Redefined for all nodes to include the "SvelteStyle-" prefix | ||
| "parent" // Redefined for Root | ||
| "walk" // The rest are redefined for Container | ||
| "walkDecls" | ||
| "walkRules" | ||
| "walkAtRules" | ||
| "walkComments" | ||
| "append" | ||
| "prepend"; | ||
|
||
type ESLintCompatiblePostCSSContainer< | ||
PostCSSNode extends Node, | ||
Child extends Node | ||
> = Omit<Container<ESLintCompatiblePostCSSNode<Child>>, RedefinedProperties> & { | ||
walk( | ||
callback: ( | ||
node: ESLintCompatiblePostCSSNode<ChildNode>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkDecls( | ||
propFilter: string | RegExp, | ||
callback: ( | ||
decl: ESLintCompatiblePostCSSNode<Declaration>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkDecls( | ||
callback: ( | ||
decl: ESLintCompatiblePostCSSNode<Declaration>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkRules( | ||
selectorFilter: string | RegExp, | ||
callback: ( | ||
rule: ESLintCompatiblePostCSSNode<Rule>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkRules( | ||
callback: ( | ||
rule: ESLintCompatiblePostCSSNode<Rule>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkAtRules( | ||
nameFilter: string | RegExp, | ||
callback: ( | ||
atRule: ESLintCompatiblePostCSSNode<AtRule>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkAtRules( | ||
callback: ( | ||
atRule: ESLintCompatiblePostCSSNode<AtRule>, | ||
index: number | ||
) => false | void | ||
): false | undefined; | ||
walkComments( | ||
callback: ( | ||
comment: ESLintCompatiblePostCSSNode<Comment>, | ||
indexed: number | ||
) => false | void | ||
): false | undefined; | ||
walkComments( | ||
callback: ( | ||
comment: ESLintCompatiblePostCSSNode<Comment>, | ||
indexed: number | ||
) => false | void | ||
): false | undefined; | ||
append( | ||
...nodes: ( | ||
| ESLintCompatiblePostCSSNode<Node> | ||
| ESLintCompatiblePostCSSNode<Node>[] | ||
| ChildProps | ||
| ChildProps[] | ||
| string | ||
| string[] | ||
)[] | ||
): ESLintCompatiblePostCSSNode<PostCSSNode>; | ||
prepend( | ||
...nodes: ( | ||
| ESLintCompatiblePostCSSNode<Node> | ||
| ESLintCompatiblePostCSSNode<Node>[] | ||
| ChildProps | ||
| ChildProps[] | ||
| string | ||
| string[] | ||
)[] | ||
): ESLintCompatiblePostCSSNode<PostCSSNode>; | ||
}; | ||
|
||
export type ESLintCompatiblePostCSSNode<PostCSSNode extends Node> = | ||
// The following hack makes the `type` property work for type narrowing, see microsoft/TypeScript#53887. | ||
PostCSSNode extends any | ||
? Locations & | ||
Omit<PostCSSNode, RedefinedProperties> & { | ||
type: `SvelteStyle-${PostCSSNode["type"]}`; | ||
} & (PostCSSNode extends Container<infer Child> | ||
? ESLintCompatiblePostCSSContainer<PostCSSNode, Child> | ||
: unknown) & | ||
(PostCSSNode extends Root | ||
? { | ||
parent: SvelteStyleElement; | ||
} | ||
: { | ||
parent: PostCSSNode["parent"]; | ||
}) | ||
: never; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not the right thing to do...