Skip to content

Commit

Permalink
Merge pull request #183 from wongjn/scss-modules
Browse files Browse the repository at this point in the history
SCSS modules
  • Loading branch information
octref committed Nov 26, 2019
2 parents 5badb54 + 54c9ef6 commit 2f0c191
Show file tree
Hide file tree
Showing 12 changed files with 745 additions and 18 deletions.
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

0 comments on commit 2f0c191

Please sign in to comment.