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

Side by Side Diff: lib/src/compiler.dart

Issue 11275029: Support for specifying an output directory (issue #106) (Closed) Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library compiler; 5 library compiler;
6 6
7 import 'dart:coreimpl'; 7 import 'dart:coreimpl';
8 import 'package:html5lib/dom.dart'; 8 import 'package:html5lib/dom.dart';
9 import 'package:html5lib/parser.dart'; 9 import 'package:html5lib/parser.dart';
10 10
11 import 'analyzer.dart'; 11 import 'analyzer.dart';
12 import 'code_printer.dart'; 12 import 'code_printer.dart';
13 import 'codegen.dart' as codegen; 13 import 'codegen.dart' as codegen;
14 import 'directive_parser.dart' show parseDartCode;
14 import 'emitters.dart'; 15 import 'emitters.dart';
15 import 'messages.dart';
16 import 'file_system.dart'; 16 import 'file_system.dart';
17 import 'file_system/path.dart'; 17 import 'file_system/path.dart';
18 import 'files.dart'; 18 import 'files.dart';
19 import 'info.dart'; 19 import 'info.dart';
20 import 'messages.dart';
20 import 'options.dart'; 21 import 'options.dart';
21 import 'utils.dart'; 22 import 'utils.dart';
22 23
23 24
24 /** 25 /**
25 * Parses an HTML file [contents] and returns a DOM-like tree. 26 * Parses an HTML file [contents] and returns a DOM-like tree.
26 * Note that [contents] will be a [String] if coming from a browser-based 27 * Note that [contents] will be a [String] if coming from a browser-based
27 * [FileSystem], or it will be a [List<int>] if running on the command line. 28 * [FileSystem], or it will be a [List<int>] if running on the command line.
28 */ 29 */
29 Document parseHtml(contents, Path sourcePath) { 30 Document parseHtml(contents, Path sourcePath) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 /** Parse [filename] and treat it as a .dart file. */ 116 /** Parse [filename] and treat it as a .dart file. */
116 Future<SourceFile> _parseDartFile(Path path) { 117 Future<SourceFile> _parseDartFile(Path path) {
117 return filesystem.readText(path).transform( 118 return filesystem.readText(path).transform(
118 (source) => new SourceFile(path, isDart: true)..code = source); 119 (source) => new SourceFile(path, isDart: true)..code = source);
119 } 120 }
120 121
121 void _addDartFile(SourceFile dartFile) { 122 void _addDartFile(SourceFile dartFile) {
122 var fileInfo = new FileInfo(dartFile.path); 123 var fileInfo = new FileInfo(dartFile.path);
123 info[dartFile.path] = fileInfo; 124 info[dartFile.path] = fileInfo;
124 fileInfo.inlinedCode = dartFile.code; 125 fileInfo.inlinedCode = dartFile.code;
126 fileInfo.userCode = parseDartCode(fileInfo.inlinedCode, messages);
127 if (fileInfo.userCode.partOf != null) {
128 messages.error('expected a library, not a part.', null,
129 file: dartFile.path);
130 }
131
125 files.add(dartFile); 132 files.add(dartFile);
126 } 133 }
127 134
128 /** Run the analyzer on every input html file. */ 135 /** Run the analyzer on every input html file. */
129 void _analyze() { 136 void _analyze() {
130 for (var file in files) { 137 for (var file in files) {
131 if (file.isDart) continue; 138 if (file.isDart) continue;
132 _time('Analyzed contents', file.path, () => analyzeFile(file, info)); 139 _time('Analyzed contents', file.path, () => analyzeFile(file, info));
133 } 140 }
134 } 141 }
(...skipping 18 matching lines...) Expand all
153 }); 160 });
154 } 161 }
155 } 162 }
156 163
157 static const String DARTJS_LOADER = 164 static const String DARTJS_LOADER =
158 "http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"; 165 "http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js";
159 166
160 /** Emit the main .dart file. */ 167 /** Emit the main .dart file. */
161 void _emitMainDart(SourceFile file) { 168 void _emitMainDart(SourceFile file) {
162 var fileInfo = info[file.path]; 169 var fileInfo = info[file.path];
163 var contents = new MainPageEmitter(fileInfo).run(file.document); 170 var contents = new MainPageEmitter(fileInfo).run(file.document, _pathInfo);
164 output.add(new OutputFile(_pathInfo.outputLibraryPath(fileInfo), contents)); 171 output.add(new OutputFile(_pathInfo.outputLibraryPath(fileInfo), contents));
165 } 172 }
166 173
167 /** Generate an html file with the (trimmed down) main html page. */ 174 /** Generate an html file with the (trimmed down) main html page. */
168 void _emitMainHtml(SourceFile file) { 175 void _emitMainHtml(SourceFile file) {
169 var fileInfo = info[file.path]; 176 var fileInfo = info[file.path];
170 177
171 // Clear the body, we moved all of it 178 // Clear the body, we moved all of it
172 var document = file.document; 179 var document = file.document;
173 document.body.nodes.clear(); 180 document.body.nodes.clear();
(...skipping 18 matching lines...) Expand all
192 _addAutoGeneratedComment(file); 199 _addAutoGeneratedComment(file);
193 output.add(new OutputFile( 200 output.add(new OutputFile(
194 _pathInfo.fileInOutputDir('_${file.path.filename}.html'), 201 _pathInfo.fileInOutputDir('_${file.path.filename}.html'),
195 document.outerHTML)); 202 document.outerHTML));
196 } 203 }
197 204
198 /** Emits the Dart code for all components in the [file]. */ 205 /** Emits the Dart code for all components in the [file]. */
199 void _emitComponents(SourceFile file) { 206 void _emitComponents(SourceFile file) {
200 var fileInfo = info[file.path]; 207 var fileInfo = info[file.path];
201 for (var component in fileInfo.declaredComponents) { 208 for (var component in fileInfo.declaredComponents) {
202 var code = new WebComponentEmitter(fileInfo).run(component); 209 var code = new WebComponentEmitter(fileInfo).run(component, _pathInfo);
203 output.add(new OutputFile(_pathInfo.outputLibraryPath(component), code)); 210 output.add(new OutputFile(_pathInfo.outputLibraryPath(component), code));
204 } 211 }
205 } 212 }
206 213
207 /** Emit the wrapper .dart file for a component page. */ 214 /** Emit the wrapper .dart file for a component page. */
208 void _emitComponentDart(SourceFile file) { 215 void _emitComponentDart(SourceFile file) {
209 var fileInfo = info[file.path]; 216 var fileInfo = info[file.path];
210 // Reexport all components declared in the input file. 217 // Reexport all components declared in the input file.
211 var exports = fileInfo.declaredComponents.map( 218 var exports = fileInfo.declaredComponents.map(
212 (c) => PathInfo.relativePath(fileInfo, c)); 219 (c) => PathInfo.relativePath(fileInfo, c));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (doctype.tagName != 'html' || commentIndex != 1) { 267 if (doctype.tagName != 'html' || commentIndex != 1) {
261 messages.warning('file should start with <!DOCTYPE html> ' 268 messages.warning('file should start with <!DOCTYPE html> '
262 'to avoid the possibility of it being parsed in quirks mode in IE. ' 269 'to avoid the possibility of it being parsed in quirks mode in IE. '
263 'See http://www.w3.org/TR/html5-diff/#doctype', 270 'See http://www.w3.org/TR/html5-diff/#doctype',
264 doctype.span, file: file.path); 271 doctype.span, file: file.path);
265 } 272 }
266 } 273 }
267 document.nodes.insertAt(commentIndex, parseFragment( 274 document.nodes.insertAt(commentIndex, parseFragment(
268 '\n<!-- This file was auto-generated from template ${file.path}. -->\n')); 275 '\n<!-- This file was auto-generated from template ${file.path}. -->\n'));
269 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698