Skip to content

SCSS modules #183

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

Merged
merged 35 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9fa8bc8
Recognize @use
wongjn Oct 12, 2019
0036d50
Add support for @use explicit namespacing
wongjn Oct 12, 2019
a205cb7
Add wildcard expansion for @use
wongjn Oct 12, 2019
27755ce
Set @use identifier from 'as' statement
wongjn Oct 12, 2019
698ead9
Parse @use with configuration
wongjn Oct 12, 2019
9c516d3
Fix missing semi colon
wongjn Oct 12, 2019
8ae7985
Change use NodeType enum value
wongjn Oct 12, 2019
90f4633
Add basic @forward parsing
wongjn Oct 12, 2019
88cb645
Parse @forward 'as' syntax
wongjn Oct 12, 2019
65e3713
Parse @forward visibility modifiers
wongjn Oct 12, 2019
dd00de1
Validate keyword on @use and @forward
wongjn Oct 12, 2019
8496589
Add basic module variable parsing
wongjn Oct 12, 2019
4007c33
Parse module variables in expressions
wongjn Oct 13, 2019
760167e
Add tests for interpolated module variables
wongjn Oct 13, 2019
3861c11
Refactor parser for function module members
wongjn Oct 13, 2019
f1a6caa
Parse module members in media queries
wongjn Oct 13, 2019
f14895f
Add tests for module syntax in @keyframe
wongjn Oct 13, 2019
5c2baaf
Add tests for module syntax in @if
wongjn Oct 13, 2019
9b1d731
Add tests for module syntax in @for
wongjn Oct 13, 2019
57921a7
Support module syntax in @include
wongjn Oct 13, 2019
8b1e6a7
Display error for missing module member access
wongjn Oct 13, 2019
c125abd
Modify ruleset tests with module variables
wongjn Oct 13, 2019
e873d69
Test module syntax to selector interpolation
wongjn Oct 13, 2019
f0d32ab
Rewrite wildcard check in '@forward as'
wongjn Oct 13, 2019
b7f2191
Rework @forward and @use as special token types
wongjn Oct 15, 2019
cc6e84c
Fix @forward visibility parsing
wongjn Oct 16, 2019
d1128bd
Add completion definitions for @use and @forward
wongjn Oct 14, 2019
004c86e
Refactor module-related tests to new suite
wongjn Oct 15, 2019
a810af7
Limit module-loading at-rules to top-level scope
wongjn Oct 15, 2019
0bd11b9
Add snippets for module loaders
wongjn Oct 16, 2019
7305494
Add path completion for @forward & @use
wongjn Oct 16, 2019
a985901
Add completion for sass module built ins
wongjn Oct 19, 2019
6b026e2
Merge remote-tracking branch 'origin/master' into pr/wongjn/183
octref Nov 25, 2019
599fa99
Keep module syntax tests orthagonal
wongjn Nov 26, 2019
54c9ef6
Add document links for @forward and @use
wongjn Nov 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/parser/cssErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ export const ParseError = {
SelectorExpected: new CSSIssueType('css-selectorexpected', localize('expected.selector', "selector expected")),
StringLiteralExpected: new CSSIssueType('css-stringliteralexpected', localize('expected.stringliteral', "string literal expected")),
WhitespaceExpected: new CSSIssueType('css-whitespaceexpected', localize('expected.whitespace', "whitespace expected")),
MediaQueryExpected: new CSSIssueType('css-mediaqueryexpected', localize('expected.mediaquery', "media query expected"))
MediaQueryExpected: new CSSIssueType('css-mediaqueryexpected', localize('expected.mediaquery', "media query expected")),
IdentifierOrWildcardExpected: new CSSIssueType('css-idorwildcardexpected', localize('expected.idorwildcard', "identifier or wildcard expected")),
WildcardExpected: new CSSIssueType('css-wildcardexpected', localize('expected.wildcard', "wildcard expected")),
IdentifierOrVariableExpected: new CSSIssueType('css-idorvarexpected', localize('expected.idorvar', "identifier or variable expected")),
};
121 changes: 120 additions & 1 deletion src/parser/cssNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export enum NodeType {
GridLine,
Plugin,
UnknownAtRule,
Use,
ModuleConfiguration,
Forward,
ForwardVisibility,
Module,
}

export enum ReferenceType {
Expand All @@ -91,7 +96,10 @@ export enum ReferenceType {
Variable,
Function,
Keyframe,
Unknown
Unknown,
Module,
Forward,
ForwardVisibility,
}


Expand Down Expand Up @@ -1008,6 +1016,97 @@ export class Import extends Node {
}
}

export class Use extends Node {

public identifier?: Identifier;
public parameters?: Nodelist;

public get type(): NodeType {
return NodeType.Use;
}

public getParameters(): Nodelist {
if (!this.parameters) {
this.parameters = new Nodelist(this);
}
return this.parameters;
}

public setIdentifier(node: Identifier | null): node is Identifier {
return this.setNode('identifier', node, 0);
}

public getIdentifier(): Identifier | undefined {
return this.identifier;
}
}

export class ModuleConfiguration extends Node {

public identifier?: Node;
public value?: Node;

public get type(): NodeType {
return NodeType.ModuleConfiguration;
}

public setIdentifier(node: Node | null): node is Node {
return this.setNode('identifier', node, 0);
}

public getIdentifier(): Node | undefined {
return this.identifier;
}

public getName(): string {
return this.identifier ? this.identifier.getText() : '';
}

public setValue(node: Node | null): node is Node {
return this.setNode('value', node, 0);
}

public getValue(): Node | undefined {
return this.value;
}
}

export class Forward extends Node {

public identifier?: Node;

public get type(): NodeType {
return NodeType.Forward;
}

public setIdentifier(node: Node | null): node is Node {
return this.setNode('identifier', node, 0);
}

public getIdentifier(): Node | undefined {
return this.identifier;
}

}

export class ForwardVisibility extends Node {

public identifier?: Node;

public get type(): NodeType {
return NodeType.ForwardVisibility;
}

public setIdentifier(node: Node | null): node is Node {
return this.setNode('identifier', node, 0);
}

public getIdentifier(): Node | undefined {
return this.identifier;
}

}

export class Namespace extends Node {

constructor(offset: number, length: number) {
Expand Down Expand Up @@ -1366,6 +1465,8 @@ export class Interpolation extends Node {

export class Variable extends Node {

public module?: Module;

constructor(offset: number, length: number) {
super(offset, length);
}
Expand Down Expand Up @@ -1555,6 +1656,24 @@ export class GuardCondition extends Node {
}
}

export class Module extends Node {

public identifier?: Identifier;

public get type(): NodeType {
return NodeType.Module;
}

public setIdentifier(node: Identifier | null): node is Identifier {
return this.setNode('identifier', node, 0);
}

public getIdentifier(): Identifier | undefined {
return this.identifier;
}

}

export interface IRule {
id: string;
message: string;
Expand Down
9 changes: 8 additions & 1 deletion src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ export class Parser {

public _parseStylesheet(): nodes.Stylesheet {
const node = <nodes.Stylesheet>this.create(nodes.Stylesheet);
node.addChild(this._parseCharset());

while (node.addChild(this._parseStylesheetStart())) {
// Parse statements only valid at the beginning of stylesheets.
}

let inRecovery = false;
do {
Expand Down Expand Up @@ -285,6 +288,10 @@ export class Parser {
return this.finish(node);
}

public _parseStylesheetStart(): nodes.Node | null {
return this._parseCharset();
}

public _parseStylesheetStatement(isNested: boolean = false): nodes.Node | null {
if (this.peek(TokenType.AtKeyword)) {
return this._parseStylesheetAtStatement(isNested);
Expand Down
Loading