Remove args and logging deps, along with other cleanup (#90)
* Remove args, logging, path deps – along with binary and lib
Related to https://github.com/dart-lang/sdk/issues/35802
* require a more recent Dart SDK
diff --git a/.travis.yml b/.travis.yml
index 8681e29..f6e2d7b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: dart
dart:
- - 2.0.0
+ - 2.1.0
- dev
dart_task:
@@ -12,7 +12,7 @@
include:
- dart: dev
dartanalyzer: --fatal-infos --fatal-warnings .
- - dart: stable
+ - dart: 2.1.0
dartanalyzer: --fatal-warnings .
- dart: dev
dart_task: dartfmt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 381b38a..bb8ea79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 0.15.0
+
+- **BREAKING**
+ - Removed `css` executable from `bin` directory.
+ - Removed the deprecated `css.dart` library.
+ - `Message.level` is now of type `MessageLevel` defined in this package.
+- Removed dependencies on `package:args` and `package:logging`.
+- Require Dart SDK `>=2.1.0`.
+
## 0.14.6
* Removed whitespace between comma-delimited expressions in compact output.
diff --git a/bin/css.dart b/bin/css.dart
deleted file mode 100644
index 1aae7a8..0000000
--- a/bin/css.dart
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env dart
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// ignore: deprecated_member_use_from_same_package
-import 'package:csslib/css.dart' as css;
-
-void main(List<String> args) => css.main(args);
diff --git a/lib/css.dart b/lib/css.dart
deleted file mode 100644
index ac6510b..0000000
--- a/lib/css.dart
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-@Deprecated('Will be removed in v0.15.0')
-library css;
-
-import 'dart:io';
-
-import 'package:args/args.dart';
-import 'package:path/path.dart' as path;
-import 'package:source_span/source_span.dart';
-
-import 'parser.dart';
-import 'src/messages.dart';
-import 'visitor.dart';
-
-void main(List<String> arguments) {
- // TODO(jmesserly): fix this to return a proper exit code
- var options = _parseOptions(arguments);
- if (options == null) return;
-
- messages = Messages(options: options);
-
- _time('Total time spent on ${options.inputFile}', () {
- _compile(options.inputFile, options.verbose);
- }, true);
-}
-
-void _compile(String inputPath, bool verbose) {
- var ext = path.extension(inputPath);
- if (ext != '.css' && ext != '.scss') {
- messages.error("Please provide a CSS/Sass file", null);
- return;
- }
- try {
- // Read the file.
- var filename = path.basename(inputPath);
- var contents = File(inputPath).readAsStringSync();
- var file = SourceFile.fromString(contents, url: path.toUri(inputPath));
-
- // Parse the CSS.
- StyleSheet tree =
- _time('Parse $filename', () => Parser(file, contents).parse(), verbose);
-
- _time('Analyzer $filename', () => Analyzer([tree], messages), verbose)
- .run();
-
- // Emit the processed CSS.
- var emitter = CssPrinter();
- _time('Codegen $filename', () => emitter.visitTree(tree, pretty: true),
- verbose);
-
- // Write the contents to a file.
- var outPath = path.join(path.dirname(inputPath), '_$filename');
- File(outPath).writeAsStringSync(emitter.toString());
- } catch (e) {
- messages.error('error processing $inputPath. Original message:\n $e', null);
- }
-}
-
-T _time<T>(String message, T Function() callback, bool printTime) {
- if (!printTime) return callback();
- final watch = Stopwatch();
- watch.start();
- var result = callback();
- watch.stop();
- final duration = watch.elapsedMilliseconds;
- _printMessage(message, duration);
- return result;
-}
-
-void _printMessage(String message, int duration) {
- var buf = StringBuffer();
- buf.write(message);
- for (int i = message.length; i < 60; i++) buf.write(' ');
- buf.write(' -- ');
- if (duration < 10) buf.write(' ');
- if (duration < 100) buf.write(' ');
- buf..write(duration)..write(' ms');
- print(buf.toString());
-}
-
-PreprocessorOptions _fromArgs(ArgResults args) => PreprocessorOptions(
- warningsAsErrors: args['warnings_as_errors'],
- throwOnWarnings: args['throw_on_warnings'],
- throwOnErrors: args['throw_on_errors'],
- verbose: args['verbose'],
- checked: args['checked'],
- lessSupport: args['less'],
- useColors: args['colors'],
- polyfill: args['polyfill'],
- inputFile: args.rest.isNotEmpty ? args.rest[0] : null);
-
-// tool.dart [options...] <css file>
-PreprocessorOptions _parseOptions(List<String> arguments) {
- var parser = ArgParser()
- ..addFlag('verbose',
- abbr: 'v',
- defaultsTo: false,
- negatable: false,
- help: 'Display detail info')
- ..addFlag('checked',
- defaultsTo: false,
- negatable: false,
- help: 'Validate CSS values invalid value display a warning message')
- ..addFlag('less',
- defaultsTo: true,
- negatable: true,
- help: 'Supports subset of Less syntax')
- ..addFlag('suppress_warnings',
- defaultsTo: true, help: 'Warnings not displayed')
- ..addFlag('warnings_as_errors',
- defaultsTo: false, help: 'Warning handled as errors')
- ..addFlag('throw_on_errors',
- defaultsTo: false, help: 'Throw on errors encountered')
- ..addFlag('throw_on_warnings',
- defaultsTo: false, help: 'Throw on warnings encountered')
- ..addFlag('colors',
- defaultsTo: true, help: 'Display errors/warnings in colored text')
- ..addFlag('polyfill',
- defaultsTo: false, help: 'Generate polyfill for new CSS features')
- ..addFlag('help',
- abbr: 'h',
- defaultsTo: false,
- negatable: false,
- help: 'Displays this help message');
-
- try {
- var results = parser.parse(arguments);
- if (results['help'] || results.rest.isEmpty) {
- _showUsage(parser);
- return null;
- }
- return _fromArgs(results);
- } on FormatException catch (e) {
- print(e.message);
- _showUsage(parser);
- return null;
- }
-}
-
-void _showUsage(ArgParser parser) {
- print('Usage: css [options...] input.css');
- print(parser.usage);
-}
diff --git a/lib/parser.dart b/lib/parser.dart
index 7680683..5fca910 100644
--- a/lib/parser.dart
+++ b/lib/parser.dart
@@ -2,26 +2,24 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library csslib.parser;
-
import 'dart:math' as math;
import 'package:source_span/source_span.dart';
import 'src/messages.dart';
-import 'src/options.dart';
+import 'src/preprocessor_options.dart';
import 'visitor.dart';
-export 'src/messages.dart' show Message;
-export 'src/options.dart';
+export 'src/messages.dart' show Message, MessageLevel;
+export 'src/preprocessor_options.dart';
part 'src/analyzer.dart';
part 'src/polyfill.dart';
part 'src/property.dart';
part 'src/token.dart';
-part 'src/tokenizer_base.dart';
+part 'src/token_kind.dart';
part 'src/tokenizer.dart';
-part 'src/tokenkind.dart';
+part 'src/tokenizer_base.dart';
enum ClauseType {
none,
diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart
index 6421c6e..5f34da5 100644
--- a/lib/src/analyzer.dart
+++ b/lib/src/analyzer.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.parser;
+part of '../parser.dart';
// TODO(terry): Add optimizing phase to remove duplicated selectors in the same
// selector group (e.g., .btn, .btn { color: red; }). Also, look
diff --git a/lib/src/css_printer.dart b/lib/src/css_printer.dart
index 552f25e..a95fa34 100644
--- a/lib/src/css_printer.dart
+++ b/lib/src/css_printer.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.visitor;
+part of '../visitor.dart';
/// Visitor that produces a formatted string representation of the CSS tree.
class CssPrinter extends Visitor {
diff --git a/lib/src/messages.dart b/lib/src/messages.dart
index 17d1acf..edc72d8 100644
--- a/lib/src/messages.dart
+++ b/lib/src/messages.dart
@@ -2,12 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library csslib.src.messages;
-
-import 'package:logging/logging.dart' show Level;
import 'package:source_span/source_span.dart';
-import 'options.dart';
+import 'preprocessor_options.dart';
+
+enum MessageLevel { info, warning, severe }
// TODO(terry): Remove the global messages, use some object that tracks
// compilation state.
@@ -16,32 +15,28 @@
Messages messages;
// Color constants used for generating messages.
-final String GREEN_COLOR = '\u001b[32m';
-final String RED_COLOR = '\u001b[31m';
-final String MAGENTA_COLOR = '\u001b[35m';
-final String NO_COLOR = '\u001b[0m';
+const _greenColor = '\u001b[32m';
+const _redColor = '\u001b[31m';
+const _magentaColor = '\u001b[35m';
+const _noColor = '\u001b[0m';
/// Map between error levels and their display color.
-final Map<Level, String> _ERROR_COLORS = (() {
- var colorsMap = Map<Level, String>();
- colorsMap[Level.SEVERE] = RED_COLOR;
- colorsMap[Level.WARNING] = MAGENTA_COLOR;
- colorsMap[Level.INFO] = GREEN_COLOR;
- return colorsMap;
-})();
+const Map<MessageLevel, String> _errorColors = {
+ MessageLevel.severe: _redColor,
+ MessageLevel.warning: _magentaColor,
+ MessageLevel.info: _greenColor,
+};
/// Map between error levels and their friendly name.
-final Map<Level, String> _ERROR_LABEL = (() {
- var labels = Map<Level, String>();
- labels[Level.SEVERE] = 'error';
- labels[Level.WARNING] = 'warning';
- labels[Level.INFO] = 'info';
- return labels;
-})();
+const Map<MessageLevel, String> _errorLabel = {
+ MessageLevel.severe: 'error',
+ MessageLevel.warning: 'warning',
+ MessageLevel.info: 'info',
+};
/// A single message from the compiler.
class Message {
- final Level level;
+ final MessageLevel level;
final String message;
final SourceSpan span;
final bool useColors;
@@ -52,11 +47,11 @@
String toString() {
var output = StringBuffer();
- bool colors = useColors && _ERROR_COLORS.containsKey(level);
- var levelColor = colors ? _ERROR_COLORS[level] : null;
+ bool colors = useColors && _errorColors.containsKey(level);
+ var levelColor = colors ? _errorColors[level] : null;
if (colors) output.write(levelColor);
- output..write(_ERROR_LABEL[level])..write(' ');
- if (colors) output.write(NO_COLOR);
+ output..write(_errorLabel[level])..write(' ');
+ if (colors) output.write(_noColor);
if (span == null) {
output.write(message);
@@ -69,13 +64,11 @@
}
}
-typedef PrintHandler = void Function(Message obj);
-
/// This class tracks and prints information, warnings, and errors emitted by
/// the compiler.
class Messages {
/// Called on every error. Set to blank function to supress printing.
- final PrintHandler printHandler;
+ final void Function(Message obj) printHandler;
final PreprocessorOptions options;
@@ -86,7 +79,7 @@
/// Report a compile-time CSS error.
void error(String message, SourceSpan span) {
- var msg = Message(Level.SEVERE, message,
+ var msg = Message(MessageLevel.severe, message,
span: span, useColors: options.useColors);
messages.add(msg);
@@ -99,7 +92,7 @@
if (options.warningsAsErrors) {
error(message, span);
} else {
- var msg = Message(Level.WARNING, message,
+ var msg = Message(MessageLevel.warning, message,
span: span, useColors: options.useColors);
messages.add(msg);
@@ -108,8 +101,8 @@
/// Report and informational message about what the compiler is doing.
void info(String message, SourceSpan span) {
- var msg =
- Message(Level.INFO, message, span: span, useColors: options.useColors);
+ var msg = Message(MessageLevel.info, message,
+ span: span, useColors: options.useColors);
messages.add(msg);
@@ -120,7 +113,8 @@
void mergeMessages(Messages newMessages) {
messages.addAll(newMessages.messages);
newMessages.messages
- .where((message) => message.level == Level.SEVERE || options.verbose)
+ .where((message) =>
+ message.level == MessageLevel.severe || options.verbose)
.forEach(printHandler);
}
}
diff --git a/lib/src/polyfill.dart b/lib/src/polyfill.dart
index c8a01f1..d9c1b73 100644
--- a/lib/src/polyfill.dart
+++ b/lib/src/polyfill.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.parser;
+part of '../parser.dart';
/// CSS polyfill emits CSS to be understood by older parsers that which do not
/// understand (var, calc, etc.).
diff --git a/lib/src/options.dart b/lib/src/preprocessor_options.dart
similarity index 97%
rename from lib/src/options.dart
rename to lib/src/preprocessor_options.dart
index 3300cf6..8df2680 100644
--- a/lib/src/options.dart
+++ b/lib/src/preprocessor_options.dart
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library csslib.src.options;
-
class PreprocessorOptions {
/// Generate polyfill code (e.g., var, etc.)
final bool polyfill;
diff --git a/lib/src/property.dart b/lib/src/property.dart
index de74760..01fc96b 100644
--- a/lib/src/property.dart
+++ b/lib/src/property.dart
@@ -4,7 +4,7 @@
/// Representations of CSS styles.
-part of csslib.parser;
+part of '../parser.dart';
// TODO(terry): Prune down this file we do need some of the code in this file
// for darker, lighter, how to represent a Font, etc but alot of
diff --git a/lib/src/token.dart b/lib/src/token.dart
index 873c217..f29850f 100644
--- a/lib/src/token.dart
+++ b/lib/src/token.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.parser;
+part of '../parser.dart';
/// A single token in the Dart language.
class Token {
diff --git a/lib/src/tokenkind.dart b/lib/src/token_kind.dart
similarity index 99%
rename from lib/src/tokenkind.dart
rename to lib/src/token_kind.dart
index af6233e..ec92170 100644
--- a/lib/src/tokenkind.dart
+++ b/lib/src/token_kind.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.parser;
+part of '../parser.dart';
// TODO(terry): Need to be consistent with tokens either they're ASCII tokens
// e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
diff --git a/lib/src/tokenizer.dart b/lib/src/tokenizer.dart
index a09e306..724f5b7 100644
--- a/lib/src/tokenizer.dart
+++ b/lib/src/tokenizer.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.parser;
+part of '../parser.dart';
class Tokenizer extends TokenizerBase {
/// U+ prefix for unicode characters.
diff --git a/lib/src/tokenizer_base.dart b/lib/src/tokenizer_base.dart
index a856727..a12471d 100644
--- a/lib/src/tokenizer_base.dart
+++ b/lib/src/tokenizer_base.dart
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
// Generated by scripts/tokenizer_gen.py.
-part of csslib.parser;
+part of '../parser.dart';
/// Tokenizer state to support look ahead for Less' nested selectors.
class TokenizerState {
diff --git a/lib/src/tree.dart b/lib/src/tree.dart
index fa66422..be5aff1 100644
--- a/lib/src/tree.dart
+++ b/lib/src/tree.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.visitor;
+part of '../visitor.dart';
/////////////////////////////////////////////////////////////////////////
// CSS specific types:
diff --git a/lib/src/tree_base.dart b/lib/src/tree_base.dart
index 8338ad3..d8fee1d 100644
--- a/lib/src/tree_base.dart
+++ b/lib/src/tree_base.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.visitor;
+part of '../visitor.dart';
/// The base type for all nodes in a CSS abstract syntax tree.
abstract class TreeNode {
diff --git a/lib/src/tree_printer.dart b/lib/src/tree_printer.dart
index 2371015..6ed6962 100644
--- a/lib/src/tree_printer.dart
+++ b/lib/src/tree_printer.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of csslib.visitor;
+part of '../visitor.dart';
// TODO(terry): Enable class for debug only; when conditional imports enabled.
diff --git a/lib/src/validate.dart b/lib/src/validate.dart
index 6e903b6..e6d66f2 100644
--- a/lib/src/validate.dart
+++ b/lib/src/validate.dart
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library csslib.src.validate;
-
import 'package:csslib/visitor.dart';
import 'package:source_span/source_span.dart';
diff --git a/lib/visitor.dart b/lib/visitor.dart
index 7b411cd..e21cff7 100644
--- a/lib/visitor.dart
+++ b/lib/visitor.dart
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library csslib.visitor;
-
import 'package:source_span/source_span.dart';
import 'parser.dart';
diff --git a/pubspec.yaml b/pubspec.yaml
index c928dbd..2922e0b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,17 +1,14 @@
name: csslib
-version: 0.14.6
+version: 0.15.0-dev
description: A library for parsing CSS.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/csslib
environment:
- sdk: '>=2.0.0 <3.0.0'
+ sdk: '>=2.1.0 <3.0.0'
dependencies:
- args: ^1.4.3
- logging: ^0.11.3
- path: ^1.6.1
source_span: ^1.4.0
dev_dependencies:
diff --git a/test/testing.dart b/test/testing.dart
index 28b707d..345e5b6 100644
--- a/test/testing.dart
+++ b/test/testing.dart
@@ -8,9 +8,9 @@
import 'package:csslib/parser.dart';
import 'package:csslib/visitor.dart';
import 'package:csslib/src/messages.dart';
-import 'package:csslib/src/options.dart';
+import 'package:csslib/src/preprocessor_options.dart';
-export 'package:csslib/src/options.dart';
+export 'package:csslib/src/preprocessor_options.dart';
const simpleOptionsWithCheckedAndWarningsAsErrors = PreprocessorOptions(
useColors: false,