Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Unified Diff: pkg/polymer/lib/src/transform/code_extractor.dart

Issue 23757034: Rearranges the polymer package now that the old compiler is gone. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/polymer/lib/src/transform.dart ('k') | pkg/polymer/lib/src/transform/common.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/transform/code_extractor.dart
diff --git a/pkg/polymer/lib/src/transform/code_extractor.dart b/pkg/polymer/lib/src/transform/code_extractor.dart
deleted file mode 100644
index 580f5ac141e923cc8a5da1390bcc0a6cceaa5050..0000000000000000000000000000000000000000
--- a/pkg/polymer/lib/src/transform/code_extractor.dart
+++ /dev/null
@@ -1,83 +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.
-
-/** Transfomer that extracts inlined script code into separate assets. */
-library polymer.src.transformers;
-
-import 'dart:async';
-
-import 'package:analyzer_experimental/src/generated/ast.dart';
-import 'package:analyzer_experimental/src/generated/error.dart';
-import 'package:analyzer_experimental/src/generated/parser.dart';
-import 'package:analyzer_experimental/src/generated/scanner.dart';
-import 'package:barback/barback.dart';
-import 'package:path/path.dart' as path;
-
-import 'common.dart';
-
-/**
- * Transformer that extracts Dart code inlined in HTML script tags and outputs a
- * separate file for each.
- */
-class InlineCodeExtractor extends Transformer with PolymerTransformer {
- final TransformOptions options;
-
- InlineCodeExtractor(this.options);
-
- /** Only run this transformer on .html files. */
- final String allowedExtensions = ".html";
-
- Future apply(Transform transform) {
- var input = transform.primaryInput;
- var id = transform.primaryInput.id;
- return readPrimaryAsHtml(transform).then((document) {
- int count = 0;
- bool htmlChanged = false;
- for (var tag in document.queryAll('script')) {
- // Only process tags that have inline Dart code
- if (tag.attributes['type'] != 'application/dart' ||
- tag.attributes.containsKey('src')) {
- continue;
- }
- htmlChanged = true;
-
- // Remove empty tags
- if (tag.nodes.length == 0) {
- tag.remove();
- continue;
- }
-
- var filename = path.url.basename(id.path);
- // TODO(sigmund): ensure this filename is unique (dartbug.com/12618).
- tag.attributes['src'] = '$filename.$count.dart';
- var textContent = tag.nodes.first;
- var code = textContent.value;
- var newId = id.addExtension('.$count.dart');
- if (!_hasLibraryDirective(code)) {
- var libname = path.withoutExtension(newId.path)
- .replaceAll(new RegExp('[-./]'), '_');
- code = "library $libname;\n$code";
- }
- transform.addOutput(new Asset.fromString(newId, code));
- textContent.remove();
- count++;
- }
- transform.addOutput(
- htmlChanged ? new Asset.fromString(id, document.outerHtml) : input);
- });
- }
-}
-
-/** Parse [code] and determine whether it has a library directive. */
-bool _hasLibraryDirective(String code) {
- var errorListener = new _ErrorCollector();
- var token = new StringScanner(null, code, errorListener).tokenize();
- var unit = new Parser(null, errorListener).parseCompilationUnit(token);
- return unit.directives.any((d) => d is LibraryDirective);
-}
-
-class _ErrorCollector extends AnalysisErrorListener {
- final errors = <AnalysisError>[];
- onError(error) => errors.add(error);
-}
« no previous file with comments | « pkg/polymer/lib/src/transform.dart ('k') | pkg/polymer/lib/src/transform/common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698