Chromium Code Reviews| Index: pkg/polymer/lib/src/compiler.dart |
| diff --git a/pkg/polymer/lib/src/compiler.dart b/pkg/polymer/lib/src/compiler.dart |
| index 5e2c98f4238019f05062a9c45941b43928d780fe..c5a5733ffadad0eeb57dd4966f03bbd455a3fbfd 100644 |
| --- a/pkg/polymer/lib/src/compiler.dart |
| +++ b/pkg/polymer/lib/src/compiler.dart |
| @@ -12,7 +12,6 @@ import 'package:analyzer_experimental/src/generated/ast.dart' show Directive, Ur |
| 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'; |
| @@ -23,13 +22,11 @@ import 'css_analyzer.dart' show analyzeCss, findUrlsImported, |
| import 'css_emitters.dart' show rewriteCssUris, |
| emitComponentStyleSheet, emitOriginalCss, emitStyleSheet; |
| import 'dart_parser.dart'; |
| -import 'emitters.dart'; |
| import 'file_system.dart'; |
| import 'files.dart'; |
| import 'info.dart'; |
| import 'messages.dart'; |
| import 'compiler_options.dart'; |
| -import 'paths.dart'; |
| import 'utils.dart'; |
| /** |
| @@ -57,12 +54,10 @@ class Compiler { |
| final FileSystem fileSystem; |
| final CompilerOptions options; |
| final List<SourceFile> files = <SourceFile>[]; |
| - final List<OutputFile> output = <OutputFile>[]; |
| String _mainPath; |
| String _resetCssFile; |
| StyleSheet _cssResetStyleSheet; |
| - PathMapper _pathMapper; |
| Messages _messages; |
| FutureGroup _tasks; |
| @@ -79,9 +74,6 @@ class Compiler { |
| _mainPath = options.inputFile; |
| var mainDir = path.dirname(_mainPath); |
| var baseDir = options.baseDir != null ? options.baseDir : mainDir; |
| - var outputDir = options.outputDir != null ? options.outputDir : mainDir; |
| - var packageRoot = options.packageRoot != null ? options.packageRoot |
|
Jennifer Messerly
2013/08/28 22:25:45
we might want pkg root back now?
Siggi Cherem (dart-lang)
2013/08/28 23:17:06
Done.
|
| - : path.join(path.dirname(_mainPath), 'packages'); |
| if (options.resetCssFile != null) { |
| _resetCssFile = options.resetCssFile; |
| @@ -92,18 +84,10 @@ class Compiler { |
| } |
| // Normalize paths - all should be relative or absolute paths. |
| - if (path.isAbsolute(_mainPath) || path.isAbsolute(baseDir) || |
| - path.isAbsolute(outputDir) || path.isAbsolute(packageRoot)) { |
| + if (path.isAbsolute(_mainPath) || path.isAbsolute(baseDir)) { |
| if (path.isRelative(_mainPath)) _mainPath = path.resolve(_mainPath); |
| if (path.isRelative(baseDir)) baseDir = path.resolve(baseDir); |
| - if (path.isRelative(outputDir)) outputDir = path.resolve(outputDir); |
| - if (path.isRelative(packageRoot)) { |
| - packageRoot = path.resolve(packageRoot); |
| - } |
| } |
| - _pathMapper = new PathMapper( |
| - baseDir, outputDir, packageRoot, options.forceMangle, |
| - options.rewriteUrls); |
| } |
| /** Compile the application starting from the given input file. */ |
| @@ -118,15 +102,9 @@ class Compiler { |
| // Analyze all CSS files. |
| _time('Analyzed Style Sheets', '', () => |
| - analyzeCss(_pathMapper.packageRoot, files, info, |
| + analyzeCss(files, info, |
| global.pseudoElements, _messages, |
| warningsAsErrors: options.warningsAsErrors)); |
| - |
| - // TODO(jmesserly): need to go through our errors, and figure out if some |
| - // of them should be warnings instead. |
| - if (_messages.hasErrors || options.analysisOnly) return; |
| - _transformDart(); |
| - _emit(); |
| }); |
| } |
| @@ -152,7 +130,7 @@ class Compiler { |
| var fileInfo = _time('Analyzed definitions', inputUrl.url, () { |
| return analyzeDefinitions(global, inputUrl, file.document, |
| - _pathMapper.packageRoot, _messages, isEntryPoint: isEntryPoint); |
| + _messages, isEntryPoint: isEntryPoint); |
| }); |
| info[inputUrl.resolvedPath] = fileInfo; |
| @@ -162,7 +140,6 @@ class Compiler { |
| null))); |
| } |
| - _setOutputFilenames(fileInfo); |
| _processImports(fileInfo); |
| // Load component files referenced by [file]. |
| @@ -180,7 +157,7 @@ class Compiler { |
| // Process any @imports inside of a <style> tag. |
| var urlInfos = findUrlsImported(fileInfo, fileInfo.inputUrl, |
| - _pathMapper.packageRoot, file.document, _messages, options); |
| + file.document, _messages, options); |
| for (var urlInfo in urlInfos) { |
| _loadFile(urlInfo, _parseCssFile); |
| } |
| @@ -195,8 +172,8 @@ class Compiler { |
| // Process any @imports inside of the <style> tag in a component. |
| var urlInfos = findUrlsImported(component, |
| - component.declaringFile.inputUrl, _pathMapper.packageRoot, |
| - component.element, _messages, options); |
| + component.declaringFile.inputUrl, component.element, _messages, |
| + options); |
| for (var urlInfo in urlInfos) { |
| _loadFile(urlInfo, _parseCssFile); |
| } |
| @@ -216,36 +193,8 @@ class Compiler { |
| } |
| } |
| - void _setOutputFilenames(FileInfo fileInfo) { |
| - var filePath = fileInfo.dartCodeUrl.resolvedPath; |
| - fileInfo.outputFilename = _pathMapper.mangle(path.basename(filePath), |
| - '.dart', path.extension(filePath) == '.html'); |
| - for (var component in fileInfo.declaredComponents) { |
| - var externalFile = component.externalFile; |
| - var name = null; |
| - if (externalFile != null) { |
| - name = _pathMapper.mangle( |
| - path.basename(externalFile.resolvedPath), '.dart'); |
| - } else { |
| - var declaringFile = component.declaringFile; |
| - var prefix = path.basename(declaringFile.inputUrl.resolvedPath); |
| - if (declaringFile.declaredComponents.length == 1 |
| - && !declaringFile.codeAttached && !declaringFile.isEntryPoint) { |
| - name = _pathMapper.mangle(prefix, '.dart', true); |
| - } else { |
| - var componentName = component.tagName.replaceAll('-', '_'); |
| - name = _pathMapper.mangle('${prefix}_$componentName', '.dart', true); |
| - } |
| - } |
| - component.outputFilename = name; |
| - } |
| - } |
| - |
| /** Parse an HTML file. */ |
| Future _parseHtmlFile(UrlInfo inputUrl) { |
| - if (!_pathMapper.checkInputPath(inputUrl, _messages)) { |
| - return new Future<SourceFile>.value(null); |
| - } |
| var filePath = inputUrl.resolvedPath; |
| return fileSystem.readTextOrBytes(filePath) |
| .catchError((e) => _readError(e, inputUrl)) |
| @@ -260,9 +209,6 @@ class Compiler { |
| /** Parse a Dart file. */ |
| Future _parseDartFile(UrlInfo inputUrl) { |
| - if (!_pathMapper.checkInputPath(inputUrl, _messages)) { |
| - return new Future<SourceFile>.value(null); |
| - } |
| var filePath = inputUrl.resolvedPath; |
| return fileSystem.readText(filePath) |
| .catchError((e) => _readError(e, inputUrl)) |
| @@ -276,8 +222,7 @@ class Compiler { |
| /** Parse a stylesheet file. */ |
| Future _parseCssFile(UrlInfo inputUrl) { |
| - if (!options.emulateScopedCss || |
| - !_pathMapper.checkInputPath(inputUrl, _messages)) { |
| + if (!options.emulateScopedCss) { |
| return new Future<SourceFile>.value(null); |
| } |
| var filePath = inputUrl.resolvedPath; |
| @@ -314,9 +259,6 @@ class Compiler { |
| var fileInfo = new FileInfo(inputUrl); |
| info[resolvedPath] = fileInfo; |
| fileInfo.inlinedCode = parseDartCode(resolvedPath, dartFile.code); |
| - fileInfo.outputFilename = |
| - _pathMapper.mangle(path.basename(resolvedPath), '.dart', false); |
| - |
| _processImports(fileInfo); |
| } |
| @@ -349,8 +291,7 @@ class Compiler { |
| void _resolveStyleSheetImports(UrlInfo inputUrl, String processingFile, |
| StyleSheet styleSheet) { |
| var urlInfos = _time('CSS imports', processingFile, () => |
| - findImportsInStyleSheet(styleSheet, _pathMapper.packageRoot, inputUrl, |
| - _messages)); |
| + findImportsInStyleSheet(styleSheet, inputUrl, _messages)); |
| for (var urlInfo in urlInfos) { |
| if (urlInfo == null) break; |
| @@ -374,39 +315,7 @@ class Compiler { |
| var span = library.userCode.sourceFile.span( |
| directive.offset, directive.end); |
| - return UrlInfo.resolve(uri, library.dartCodeUrl, span, |
| - _pathMapper.packageRoot, _messages); |
| - } |
| - |
| - /** |
| - * Transform Dart source code. |
| - * Currently, the only transformation is [transformObservables]. |
| - * Calls _emitModifiedDartFiles to write the transformed files. |
| - */ |
| - void _transformDart() { |
| - var libraries = _findAllDartLibraries(); |
| - |
| - var transformed = []; |
| - for (var lib in libraries) { |
| - var userCode = lib.userCode; |
| - var transaction = transformObservables(userCode.compilationUnit, |
| - userCode.sourceFile, userCode.code, _messages); |
| - if (transaction != null) { |
| - _edits[lib.userCode] = transaction; |
| - if (transaction.hasEdits) { |
| - transformed.add(lib); |
| - } else if (lib.htmlFile != null) { |
| - // All web components will be transformed too. Track that. |
| - transformed.add(lib); |
| - } |
| - } |
| - } |
| - |
| - _findModifiedDartFiles(libraries, transformed); |
| - |
| - libraries.forEach(_fixImports); |
| - |
| - _emitModifiedDartFiles(libraries); |
| + return UrlInfo.resolve(uri, library.dartCodeUrl, span, _messages); |
| } |
| /** |
| @@ -445,39 +354,6 @@ class Compiler { |
| } |
| /** |
| - * Queue modified Dart files to be written. |
| - * This will not write files that are handled by [WebComponentEmitter] and |
| - * [EntryPointEmitter]. |
| - */ |
| - void _emitModifiedDartFiles(List<LibraryInfo> libraries) { |
| - for (var lib in libraries) { |
| - // Components will get emitted by WebComponentEmitter, and the |
| - // entry point will get emitted by MainPageEmitter. |
| - // So we only need to worry about other .dart files. |
| - if (lib.modified && lib is FileInfo && |
| - lib.htmlFile == null && !lib.isEntryPoint) { |
| - var transaction = _edits[lib.userCode]; |
| - |
| - // Save imports that were modified by _fixImports. |
| - for (var d in lib.userCode.directives) { |
| - transaction.edit(d.offset, d.end, d.toString()); |
| - } |
| - |
| - if (!lib.userCode.isPart) { |
| - var pos = lib.userCode.firstPartOffset; |
| - // Note: we use a different prefix than "autogenerated" to make |
| - // ChangeRecord unambiguous. Otherwise it would be imported by this |
| - // and polymer, resulting in a collision. |
| - // TODO(jmesserly): only generate this for libraries that need it. |
| - transaction.edit(pos, pos, "\nimport " |
| - "'package:observe/observe.dart' as __observe;\n"); |
| - } |
| - _emitFileAndSourceMaps(lib, transaction.commit(), lib.dartCodeUrl); |
| - } |
| - } |
| - } |
| - |
| - /** |
| * This method computes which Dart files have been modified, starting |
| * from [transformed] and marking recursively through all files that import |
| * the modified files. |
| @@ -516,30 +392,6 @@ class Compiler { |
| } |
| } |
| - void _fixImports(LibraryInfo library) { |
| - // Fix imports. Modified files must use the generated path, otherwise |
| - // we need to make the path relative to the input. |
| - for (var directive in library.userCode.directives) { |
| - var importPath = _getDirectiveUrlInfo(library, directive); |
| - if (importPath == null) continue; |
| - var importInfo = info[importPath.resolvedPath]; |
| - if (importInfo == null) continue; |
| - |
| - String newUri = null; |
| - if (importInfo.modified) { |
| - // Use the generated URI for this file. |
| - newUri = _pathMapper.importUrlFor(library, importInfo); |
| - } else if (options.rewriteUrls) { |
| - // Get the relative path to the input file. |
| - newUri = _pathMapper.transformUrl( |
| - library.dartCodeUrl.resolvedPath, directive.uri.value); |
| - } |
| - if (newUri != null) { |
| - directive.uri = createStringLiteral(newUri); |
| - } |
| - } |
| - } |
| - |
| /** Run the analyzer on every input html file. */ |
| void _analyze() { |
| var uniqueIds = new IntIterator(); |
| @@ -552,75 +404,6 @@ class Compiler { |
| } |
| } |
| - /** Emit the generated code corresponding to each input file. */ |
| - void _emit() { |
| - for (var file in files) { |
| - if (file.isDart || file.isStyleSheet) continue; |
| - _time('Codegen', file.path, () { |
| - var fileInfo = info[file.path]; |
| - _emitComponents(fileInfo); |
| - }); |
| - } |
| - |
| - var entryPoint = files[0]; |
| - assert(info[entryPoint.path].isEntryPoint); |
| - _emitMainDart(entryPoint); |
| - _emitMainHtml(entryPoint); |
| - |
| - assert(_unqiueOutputs()); |
| - } |
| - |
| - bool _unqiueOutputs() { |
| - var seen = new Set(); |
| - for (var file in output) { |
| - if (seen.contains(file.path)) { |
| - throw new StateError('internal error: ' |
| - 'duplicate output file ${file.path}. Files were: $output'); |
| - } |
| - seen.add(file.path); |
| - } |
| - return true; |
| - } |
| - |
| - /** Emit the main .dart file. */ |
| - void _emitMainDart(SourceFile file) { |
| - var fileInfo = info[file.path]; |
| - |
| - var codeInfo = fileInfo.userCode; |
| - if (codeInfo != null) { |
| - var printer = new NestedPrinter(0); |
| - if (codeInfo.libraryName == null) { |
| - printer.addLine('library ${fileInfo.libraryName};'); |
| - } |
| - printer.add(codeInfo.code); |
| - _emitFileAndSourceMaps(fileInfo, printer, fileInfo.dartCodeUrl); |
| - } |
| - } |
| - |
| - // TODO(jmesserly): refactor this out of Compiler. |
| - /** Generate an html file with the (trimmed down) main html page. */ |
| - void _emitMainHtml(SourceFile file) { |
| - var fileInfo = info[file.path]; |
| - |
| - var bootstrapName = '${path.basename(file.path)}_bootstrap.dart'; |
| - var bootstrapPath = path.join(path.dirname(file.path), bootstrapName); |
| - var bootstrapOutPath = _pathMapper.outputPath(bootstrapPath, ''); |
| - var bootstrapOutName = path.basename(bootstrapOutPath); |
| - var bootstrapInfo = new FileInfo(new UrlInfo('', bootstrapPath, null)); |
| - var printer = generateBootstrapCode(bootstrapInfo, fileInfo, global, |
| - _pathMapper, options); |
| - printer.build(bootstrapOutPath); |
| - output.add(new OutputFile( |
| - bootstrapOutPath, printer.text, source: file.path)); |
| - |
| - var document = file.document; |
| - var hasCss = _emitAllCss(); |
| - transformMainHtml(document, fileInfo, _pathMapper, hasCss, |
| - options.rewriteUrls, _messages, global, bootstrapOutName); |
| - output.add(new OutputFile(_pathMapper.outputPath(file.path, '.html'), |
| - document.outerHtml, source: file.path)); |
| - } |
| - |
| // TODO(jmesserly): refactor this and other CSS related transforms out of |
| // Compiler. |
| /** |
| @@ -647,13 +430,6 @@ class Compiler { |
| css.write(emitStyleSheet(styleSheet, fileInfo)); |
| css.write('\n\n'); |
| } |
| - |
| - // Emit the linked style sheet in the output directory. |
| - if (fileInfo.inputUrl.url != _resetCssFile) { |
| - var outCss = _pathMapper.outputPath(fileInfo.inputUrl.resolvedPath, |
| - ''); |
| - output.add(new OutputFile(outCss, css.toString())); |
| - } |
| } |
| } |
| @@ -712,49 +488,6 @@ class Compiler { |
| return true; |
| } |
| - /** Emits the Dart code for all components in [fileInfo]. */ |
| - void _emitComponents(FileInfo fileInfo) { |
| - for (var component in fileInfo.declaredComponents) { |
| - // 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 = emitPolymerElement( |
| - component, _pathMapper, _edits[component.userCode], options); |
| - _emitFileAndSourceMaps(component, printer, component.externalFile); |
| - } |
| - } |
| - |
| - /** |
| - * Emits a file that was created using [NestedPrinter] and it's corresponding |
| - * source map file. |
| - */ |
| - void _emitFileAndSourceMaps( |
| - LibraryInfo lib, NestedPrinter printer, UrlInfo dartCodeUrl) { |
| - // Bail if we had an error generating the code for the file. |
| - if (printer == null) return; |
| - |
| - var libPath = _pathMapper.outputLibraryPath(lib); |
| - var dir = path.dirname(libPath); |
| - var filename = path.basename(libPath); |
| - printer.add('\n//# sourceMappingURL=$filename.map'); |
| - printer.build(libPath); |
| - var sourcePath = dartCodeUrl != null ? dartCodeUrl.resolvedPath : null; |
| - output.add(new OutputFile(libPath, printer.text, source: sourcePath)); |
| - // Fix-up the paths in the source map file |
| - var sourceMap = json.parse(printer.map); |
| - var urls = sourceMap['sources']; |
| - for (int i = 0; i < urls.length; i++) { |
| - urls[i] = path.relative(urls[i], from: dir); |
| - } |
| - output.add(new OutputFile(path.join(dir, '$filename.map'), |
| - json.stringify(sourceMap))); |
| - } |
| - |
| _time(String logMessage, String filePath, callback(), |
| {bool printTime: false}) { |
| var message = new StringBuffer(); |