mirror of
https://github.com/danog/dart-sass.git
synced 2024-12-02 09:37:49 +01:00
Buggy implementation of CSS @import.
This commit is contained in:
parent
47929dfde3
commit
ffb85921cb
@ -5,6 +5,7 @@
|
|||||||
export 'css/at_rule.dart';
|
export 'css/at_rule.dart';
|
||||||
export 'css/comment.dart';
|
export 'css/comment.dart';
|
||||||
export 'css/declaration.dart';
|
export 'css/declaration.dart';
|
||||||
|
export 'css/import.dart';
|
||||||
export 'css/media_query.dart';
|
export 'css/media_query.dart';
|
||||||
export 'css/media_rule.dart';
|
export 'css/media_rule.dart';
|
||||||
export 'css/node.dart';
|
export 'css/node.dart';
|
||||||
|
18
lib/src/ast/css/import.dart
Normal file
18
lib/src/ast/css/import.dart
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
||||||
|
// MIT-style license that can be found in the LICENSE file or at
|
||||||
|
// https://opensource.org/licenses/MIT.
|
||||||
|
|
||||||
|
import 'package:source_span/source_span.dart';
|
||||||
|
|
||||||
|
import '../../visitor/interface/css.dart';
|
||||||
|
import 'node.dart';
|
||||||
|
|
||||||
|
class CssImport extends CssNode {
|
||||||
|
final Uri url;
|
||||||
|
|
||||||
|
final FileSpan span;
|
||||||
|
|
||||||
|
CssImport(this.url, this.span);
|
||||||
|
|
||||||
|
/*=T*/ accept/*<T>*/(CssVisitor/*<T>*/ visitor) => visitor.visitImport(this);
|
||||||
|
}
|
@ -33,6 +33,7 @@ export 'sass/statement/import.dart';
|
|||||||
export 'sass/statement/include.dart';
|
export 'sass/statement/include.dart';
|
||||||
export 'sass/statement/media_rule.dart';
|
export 'sass/statement/media_rule.dart';
|
||||||
export 'sass/statement/mixin_declaration.dart';
|
export 'sass/statement/mixin_declaration.dart';
|
||||||
|
export 'sass/statement/plain_import.dart';
|
||||||
export 'sass/statement/return.dart';
|
export 'sass/statement/return.dart';
|
||||||
export 'sass/statement/style_rule.dart';
|
export 'sass/statement/style_rule.dart';
|
||||||
export 'sass/statement/stylesheet.dart';
|
export 'sass/statement/stylesheet.dart';
|
||||||
|
22
lib/src/ast/sass/statement/plain_import.dart
Normal file
22
lib/src/ast/sass/statement/plain_import.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
||||||
|
// MIT-style license that can be found in the LICENSE file or at
|
||||||
|
// https://opensource.org/licenses/MIT.
|
||||||
|
|
||||||
|
import 'package:source_span/source_span.dart';
|
||||||
|
|
||||||
|
import '../../../visitor/interface/statement.dart';
|
||||||
|
import '../expression/string.dart';
|
||||||
|
import '../statement.dart';
|
||||||
|
|
||||||
|
class PlainImport implements Statement {
|
||||||
|
final Uri url;
|
||||||
|
|
||||||
|
final FileSpan span;
|
||||||
|
|
||||||
|
PlainImport(this.url, this.span);
|
||||||
|
|
||||||
|
/*=T*/ accept/*<T>*/(StatementVisitor/*<T>*/ visitor) =>
|
||||||
|
visitor.visitPlainImport(this);
|
||||||
|
|
||||||
|
String toString() => "@import ${StringExpression.quoteText(url.toString())};";
|
||||||
|
}
|
@ -395,17 +395,32 @@ class Parser {
|
|||||||
return new If(expression, children, _scanner.spanFrom(start));
|
return new If(expression, children, _scanner.spanFrom(start));
|
||||||
}
|
}
|
||||||
|
|
||||||
Import _import(LineScannerState start) {
|
Statement _import(LineScannerState start) {
|
||||||
if (_inControlDirective) {
|
if (_inControlDirective) {
|
||||||
_disallowedAtRule(start);
|
_disallowedAtRule(start);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// TODO: wrap error with a span
|
// TODO: wrap error with a span
|
||||||
var url = Uri.parse(_string(static: true).text.asPlain);
|
// TODO: parse supports clauses, url(), and query lists
|
||||||
|
var urlString = _string(static: true).text.asPlain;
|
||||||
|
var url = Uri.parse(urlString);
|
||||||
|
if (_isPlainImportUrl(urlString)) {
|
||||||
|
return new PlainImport(url, _scanner.spanFrom(start));
|
||||||
|
} else {
|
||||||
return new Import(url, _scanner.spanFrom(start));
|
return new Import(url, _scanner.spanFrom(start));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isPlainImportUrl(String url) {
|
||||||
|
if (url.length < "//".length) return false;
|
||||||
|
|
||||||
|
var first = url.codeUnitAt(0);
|
||||||
|
if (first == $slash) return url.codeUnitAt(1) == $slash;
|
||||||
|
if (first != $h) return false;
|
||||||
|
return url.startsWith("http://") || url.startsWith("https://");
|
||||||
|
}
|
||||||
|
|
||||||
Include _include(LineScannerState start) {
|
Include _include(LineScannerState start) {
|
||||||
var name = _identifier();
|
var name = _identifier();
|
||||||
_ignoreComments();
|
_ignoreComments();
|
||||||
|
@ -10,6 +10,7 @@ abstract class CssVisitor<T> extends SelectorVisitor<T>
|
|||||||
implements ValueVisitor<T> {
|
implements ValueVisitor<T> {
|
||||||
T visitComment(CssComment node) => null;
|
T visitComment(CssComment node) => null;
|
||||||
T visitDeclaration(CssDeclaration node) => null;
|
T visitDeclaration(CssDeclaration node) => null;
|
||||||
|
T visitImport(CssImport node) => null;
|
||||||
|
|
||||||
T visitAtRule(CssAtRule node) {
|
T visitAtRule(CssAtRule node) {
|
||||||
if (node.children == null) return null;
|
if (node.children == null) return null;
|
||||||
|
@ -9,6 +9,7 @@ abstract class StatementVisitor<T> {
|
|||||||
T visitContent(Content node) => null;
|
T visitContent(Content node) => null;
|
||||||
T visitExtendRule(ExtendRule node) => null;
|
T visitExtendRule(ExtendRule node) => null;
|
||||||
T visitImport(Import node) => null;
|
T visitImport(Import node) => null;
|
||||||
|
T visitPlainImport(PlainImport node) => null;
|
||||||
T visitReturn(Return node) => null;
|
T visitReturn(Return node) => null;
|
||||||
T visitVariableDeclaration(VariableDeclaration node) => null;
|
T visitVariableDeclaration(VariableDeclaration node) => null;
|
||||||
|
|
||||||
|
@ -291,6 +291,9 @@ class PerformVisitor extends StatementVisitor
|
|||||||
return new CssMediaQuery(type, modifier: modifier, features: features);
|
return new CssMediaQuery(type, modifier: modifier, features: features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CssImport visitPlainImport(PlainImport node) =>
|
||||||
|
new CssImport(node.url, node.span);
|
||||||
|
|
||||||
Value visitReturn(Return node) => node.expression.accept(this);
|
Value visitReturn(Return node) => node.expression.accept(this);
|
||||||
|
|
||||||
void visitStyleRule(StyleRule node) {
|
void visitStyleRule(StyleRule node) {
|
||||||
|
@ -95,6 +95,13 @@ class _SerializeCssVisitor extends CssVisitor {
|
|||||||
_visitChildren(node.children);
|
_visitChildren(node.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void visitImport(CssImport node) {
|
||||||
|
_writeIndentation();
|
||||||
|
_buffer.write("@import ");
|
||||||
|
_visitString(node.url.toString());
|
||||||
|
_buffer.writeCharCode($semicolon);
|
||||||
|
}
|
||||||
|
|
||||||
void visitMediaQuery(CssMediaQuery query) {
|
void visitMediaQuery(CssMediaQuery query) {
|
||||||
if (query.modifier != null) {
|
if (query.modifier != null) {
|
||||||
_buffer.write(query.modifier.value);
|
_buffer.write(query.modifier.value);
|
||||||
|
Loading…
Reference in New Issue
Block a user