public _parseUse()

in src/parser/scssParser.ts [774:829]


	public _parseUse(): nodes.Node | null {
		if (!this.peekKeyword('@use')) {
			return null;
		}

		const node = <nodes.Use>this.create(nodes.Use);
		this.consumeToken(); // @use

		if (!node.addChild(this._parseStringLiteral())) {
			return this.finish(node, ParseError.StringLiteralExpected);
		}

		if (!this.peek(TokenType.SemiColon) && !this.peek(TokenType.EOF)) {
			if (!this.peekRegExp(TokenType.Ident, /as|with/)) {
				return this.finish(node, ParseError.UnknownKeyword);
			}

			if (
				this.acceptIdent('as') &&
				(!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module])) && !this.acceptDelim('*'))
			) {
				return this.finish(node, ParseError.IdentifierOrWildcardExpected);
			}

			if (this.acceptIdent('with')) {
				if (!this.accept(TokenType.ParenthesisL)) {
					return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
				}

				// First variable statement, no comma.
				if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
					return this.finish(node, ParseError.VariableNameExpected);
				}

				while (this.accept(TokenType.Comma)) {
					if (this.peek(TokenType.ParenthesisR)) {
						break;
					}
					if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
						return this.finish(node, ParseError.VariableNameExpected);
					}
				}

				if (!this.accept(TokenType.ParenthesisR)) {
					return this.finish(node, ParseError.RightParenthesisExpected);
				}

			}
		}

		if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
			return this.finish(node, ParseError.SemiColonExpected);
		}

		return this.finish(node);
	}