Skip to content

Commit

Permalink
Change variable syntax to namespace.$name (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Aug 29, 2019
1 parent 5349042 commit 8dea51d
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 184 deletions.
8 changes: 2 additions & 6 deletions lib/src/ast/selector/placeholder.dart
Expand Up @@ -2,8 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:charcode/charcode.dart';

import '../../util/character.dart' as character;
import '../../visitor/interface/selector.dart';
import '../selector.dart';

Expand All @@ -20,10 +19,7 @@ class PlaceholderSelector extends SimpleSelector {

/// Returns whether this is a private selector (that is, whether it begins
/// with `-` or `_`).
bool get isPrivate {
var start = name.codeUnitAt(0);
return start == $dash || start == $underscore;
}
bool get isPrivate => character.isPrivate(name);

PlaceholderSelector(this.name);

Expand Down
21 changes: 3 additions & 18 deletions lib/src/async_environment.dart
Expand Up @@ -48,9 +48,7 @@ class AsyncEnvironment {

/// A list of variables defined at each lexical scope level.
///
/// Each scope maps the names of declared variables to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared variables to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
Expand All @@ -67,45 +65,32 @@ class AsyncEnvironment {

/// A map of variable names to their indices in [_variables].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _variableIndices;

/// A list of functions defined at each lexical scope level.
///
/// Each scope maps the names of declared functions to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared functions to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
final List<Map<String, AsyncCallable>> _functions;

/// A map of function names to their indices in [_functions].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _functionIndices;

/// A list of mixins defined at each lexical scope level.
///
/// Each scope maps the names of declared mixins to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared mixins to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
final List<Map<String, AsyncCallable>> _mixins;

/// A map of mixin names to their indices in [_mixins].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _mixinIndices;

Expand Down
23 changes: 4 additions & 19 deletions lib/src/environment.dart
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_environment.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 587acdaa22fa4fdecfe796af866ba4dd4aa4d006
// Checksum: 1a6678b9aa71d8d8ea5aab9216a48e401a892453
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -54,9 +54,7 @@ class Environment {

/// A list of variables defined at each lexical scope level.
///
/// Each scope maps the names of declared variables to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared variables to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
Expand All @@ -73,45 +71,32 @@ class Environment {

/// A map of variable names to their indices in [_variables].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _variableIndices;

/// A list of functions defined at each lexical scope level.
///
/// Each scope maps the names of declared functions to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared functions to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
final List<Map<String, Callable>> _functions;

/// A map of function names to their indices in [_functions].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _functionIndices;

/// A list of mixins defined at each lexical scope level.
///
/// Each scope maps the names of declared mixins to their values. These
/// maps are *normalized*, meaning that they treat hyphens and underscores in
/// its keys interchangeably.
/// Each scope maps the names of declared mixins to their values.
///
/// The first element is the global scope, and each successive element is
/// deeper in the tree.
final List<Map<String, Callable>> _mixins;

/// A map of mixin names to their indices in [_mixins].
///
/// This map is *normalized*, meaning that it treats hyphens and underscores
/// in its keys interchangeably.
///
/// This map is filled in as-needed, and may not be complete.
final Map<String, int> _mixinIndices;

Expand Down
3 changes: 1 addition & 2 deletions lib/src/module/forwarded_view.dart
Expand Up @@ -11,7 +11,6 @@ import '../extend/extender.dart';
import '../module.dart';
import '../util/limited_map_view.dart';
import '../util/prefixed_map_view.dart';
import '../utils.dart';
import '../value.dart';

/// A [Module] that exposes members according to a [ForwardRule].
Expand Down Expand Up @@ -82,7 +81,7 @@ class ForwardedModuleView<T extends AsyncCallable> implements Module<T> {
}

if (_rule.prefix != null) {
if (!startsWithIgnoreSeparator(name, _rule.prefix)) {
if (!name.startsWith(_rule.prefix)) {
throw SassScriptException("Undefined variable.");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/parse/sass.dart
Expand Up @@ -159,7 +159,7 @@ class SassParser extends StylesheetParser {
return null;

case $dollar:
return variableDeclaration();
return variableDeclarationWithoutNamespace();
break;

case $slash:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parse/scss.dart
Expand Up @@ -66,7 +66,7 @@ class ScssParser extends StylesheetParser {
while (true) {
switch (scanner.peekChar()) {
case $dollar:
children.add(variableDeclaration());
children.add(variableDeclarationWithoutNamespace());
break;

case $slash:
Expand Down Expand Up @@ -107,7 +107,7 @@ class ScssParser extends StylesheetParser {
while (!scanner.isDone) {
switch (scanner.peekChar()) {
case $dollar:
statements.add(variableDeclaration());
statements.add(variableDeclarationWithoutNamespace());
break;

case $slash:
Expand Down

0 comments on commit 8dea51d

Please sign in to comment.