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

Unified Diff: lib/src/compiler.dart

Issue 22962005: Merge pull request #581 from kevmoo/polymer (Closed) Base URL: https://github.com/dart-lang/web-ui.git@polymer
Patch Set: Created 7 years, 4 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 | « lib/src/code_printer.dart ('k') | lib/src/compiler_options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler.dart
diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart
index cdb130fbb724d2f0a77eaf61c2456b73b55d0037..6c10fcf1355da615c4be7d0a7a476a659f152732 100644
--- a/lib/src/compiler.dart
+++ b/lib/src/compiler.dart
@@ -7,25 +7,29 @@ library compiler;
import 'dart:async';
import 'dart:collection' show SplayTreeMap;
import 'dart:json' as json;
+
import 'package:analyzer_experimental/src/generated/ast.dart' show Directive, UriBasedDirective;
import 'package:csslib/visitor.dart' show StyleSheet, treeToDebugString;
import 'package:html5lib/dom.dart';
import 'package:html5lib/parser.dart';
+import 'package:observe/transform.dart' show transformObservables;
import 'package:source_maps/span.dart' show Span;
+import 'package:source_maps/refactor.dart' show TextEditTransaction;
+import 'package:source_maps/printer.dart';
import 'analyzer.dart';
-import 'code_printer.dart';
+import 'css_analyzer.dart' show analyzeCss, findUrlsImported,
+ findImportsInStyleSheet, parseCss;
+import 'css_emitters.dart' show rewriteCssUris,
+ emitComponentStyleSheet, emitOriginalCss, emitStyleSheet;
import 'dart_parser.dart';
import 'emitters.dart';
import 'file_system.dart';
import 'files.dart';
-import 'html_css_fixup.dart';
import 'info.dart';
import 'messages.dart';
-import 'observable_transform.dart' show transformObservables;
import 'compiler_options.dart';
import 'paths.dart';
-import 'refactor.dart';
import 'utils.dart';
/**
@@ -152,7 +156,7 @@ class Compiler {
});
info[inputUrl.resolvedPath] = fileInfo;
- if (isEntryPoint && options.hasCssReset) {
+ if (isEntryPoint && _resetCssFile != null) {
_processed.add(_resetCssFile);
_tasks.add(_parseCssFile(new UrlInfo(_resetCssFile, _resetCssFile,
null)));
@@ -272,7 +276,7 @@ class Compiler {
/** Parse a stylesheet file. */
Future _parseCssFile(UrlInfo inputUrl) {
- if (!options.processCss ||
+ if (!options.emulateScopedCss ||
!_pathMapper.checkInputPath(inputUrl, _messages)) {
return new Future<SourceFile>.value(null);
}
@@ -309,8 +313,7 @@ class Compiler {
var resolvedPath = inputUrl.resolvedPath;
var fileInfo = new FileInfo(inputUrl);
info[resolvedPath] = fileInfo;
- fileInfo.inlinedCode =
- parseDartCode(resolvedPath, dartFile.code, _messages);
+ fileInfo.inlinedCode = parseDartCode(resolvedPath, dartFile.code);
fileInfo.outputFilename =
_pathMapper.mangle(path.basename(resolvedPath), '.dart', false);
@@ -385,7 +388,9 @@ class Compiler {
var transformed = [];
for (var lib in libraries) {
- var transaction = transformObservables(lib.userCode, _messages);
+ var userCode = lib.userCode;
+ var transaction = transformObservables(userCode.compilationUnit,
+ userCode.sourceFile, userCode.code, _messages);
if (transaction != null) {
_edits[lib.userCode] = transaction;
if (transaction.hasEdits) {
@@ -541,7 +546,8 @@ class Compiler {
for (var file in files) {
if (file.isHtml) {
_time('Analyzed contents', file.path, () =>
- analyzeFile(file, info, uniqueIds, global, _messages));
+ analyzeFile(file, info, uniqueIds, global, _messages,
+ options.emulateScopedCss));
}
}
}
@@ -552,7 +558,6 @@ class Compiler {
if (file.isDart || file.isStyleSheet) continue;
_time('Codegen', file.path, () {
var fileInfo = info[file.path];
- fixupHtmlCss(fileInfo, options);
_emitComponents(fileInfo);
});
}
@@ -583,7 +588,7 @@ class Compiler {
var codeInfo = fileInfo.userCode;
if (codeInfo != null) {
- var printer = new CodePrinter(0);
+ var printer = new NestedPrinter(0);
if (codeInfo.libraryName == null) {
printer.addLine('library ${fileInfo.libraryName};');
}
@@ -627,7 +632,7 @@ class Compiler {
* Returns true if a file was generated, otherwise false.
*/
bool _emitAllCss() {
- if (!options.processCss) return false;
+ if (!options.emulateScopedCss) return false;
var buff = new StringBuffer();
@@ -638,16 +643,8 @@ class Compiler {
if (file.isStyleSheet) {
for (var styleSheet in fileInfo.styleSheets) {
// Translate any URIs in CSS.
- var uriVisitor = new UriVisitor(_pathMapper,
- fileInfo.inputUrl.resolvedPath, options.rewriteUrls);
- uriVisitor.visitTree(styleSheet);
-
- if (options.debugCss) {
- print('\nCSS source: ${fileInfo.inputUrl.resolvedPath}');
- print('==========\n');
- print(treeToDebugString(styleSheet));
- }
-
+ rewriteCssUris(_pathMapper, fileInfo.inputUrl.resolvedPath,
+ options.rewriteUrls, styleSheet);
css.write(
'/* Auto-generated from style sheet href = ${file.path} */\n'
'/* DO NOT EDIT. */\n\n');
@@ -670,11 +667,9 @@ class Compiler {
var fileInfo = info[file.path];
for (var component in fileInfo.declaredComponents) {
for (var styleSheet in component.styleSheets) {
-
// Translate any URIs in CSS.
- var uriVisitor = new UriVisitor(_pathMapper,
- fileInfo.inputUrl.resolvedPath, options.rewriteUrls);
- uriVisitor.visitTree(styleSheet);
+ rewriteCssUris(_pathMapper, fileInfo.inputUrl.resolvedPath,
+ options.rewriteUrls, styleSheet);
if (buff.isEmpty) {
buff.write(
@@ -686,21 +681,28 @@ class Compiler {
' Component ${component.tagName} stylesheet \n'
' ==================================================== */\n');
- var cssPolyfillKind = CssPolyfillKind.of(options, component);
var tagName = component.tagName;
if (!component.hasAuthorStyles) {
- if (_cssResetStyleSheet != null && !options.mangleCss) {
+ if (_cssResetStyleSheet != null) {
// If component doesn't have apply-author-styles then we need to
// reset the CSS the styles for the component (if css-reset file
// option was passed).
buff.write('\n/* Start CSS Reset */\n');
- buff.write(emitComponentStyleSheet(_cssResetStyleSheet, tagName,
- cssPolyfillKind));
+ var style;
+ if (options.emulateScopedCss) {
+ style = emitComponentStyleSheet(_cssResetStyleSheet, tagName);
+ } else {
+ style = emitOriginalCss(_cssResetStyleSheet);
+ }
+ buff.write(style);
buff.write('/* End CSS Reset */\n\n');
}
}
- buff.write(emitComponentStyleSheet(styleSheet, tagName,
- cssPolyfillKind));
+ if (options.emulateScopedCss) {
+ buff.write(emitComponentStyleSheet(styleSheet, tagName));
+ } else {
+ buff.write(emitOriginalCss(styleSheet));
+ }
buff.write('\n\n');
}
}
@@ -717,27 +719,26 @@ class Compiler {
/** Emits the Dart code for all components in [fileInfo]. */
void _emitComponents(FileInfo fileInfo) {
for (var component in fileInfo.declaredComponents) {
- // TODO(terry): Handle one stylesheet per component see fixupHtmlCss.
- if (component.styleSheets.length > 1 && options.processCss) {
+ // TODO(terry): Handle more than one stylesheet per component
+ if (component.styleSheets.length > 1 && options.emulateScopedCss) {
var span = component.externalFile != null
? component.externalFile.sourceSpan : null;
_messages.warning(
'Component has more than one stylesheet - first stylesheet used.',
span);
}
- var printer = new WebComponentEmitter(fileInfo, _messages,
- CssPolyfillKind.of(options, component))
- .run(component, _pathMapper, _edits[component.userCode]);
+ var printer = emitPolymerElement(
+ component, _pathMapper, _edits[component.userCode], options);
_emitFileAndSourceMaps(component, printer, component.externalFile);
}
}
/**
- * Emits a file that was created using [CodePrinter] and it's corresponding
+ * Emits a file that was created using [NestedPrinter] and it's corresponding
* source map file.
*/
void _emitFileAndSourceMaps(
- LibraryInfo lib, CodePrinter printer, UrlInfo dartCodeUrl) {
+ LibraryInfo lib, NestedPrinter printer, UrlInfo dartCodeUrl) {
// Bail if we had an error generating the code for the file.
if (printer == null) return;
@@ -771,4 +772,3 @@ class Compiler {
printTime: options.verbose || printTime);
}
}
-
« no previous file with comments | « lib/src/code_printer.dart ('k') | lib/src/compiler_options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698