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

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
« no previous file with comments | « lib/src/codegen.dart ('k') | lib/src/directive_parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
127 fileInfo.path, messages);
128 if (fileInfo.userCode.partOf != null) {
129 messages.error('expected a library, not a part.', null,
130 file: dartFile.path);
131 }
132
125 files.add(dartFile); 133 files.add(dartFile);
126 } 134 }
127 135
128 /** Run the analyzer on every input html file. */ 136 /** Run the analyzer on every input html file. */
129 void _analyze() { 137 void _analyze() {
130 for (var file in files) { 138 for (var file in files) {
131 if (file.isDart) continue; 139 if (file.isDart) continue;
132 _time('Analyzed contents', file.path, () => analyzeFile(file, info)); 140 _time('Analyzed contents', file.path, () => analyzeFile(file, info));
133 } 141 }
134 } 142 }
(...skipping 18 matching lines...) Expand all
153 }); 161 });
154 } 162 }
155 } 163 }
156 164
157 static const String DARTJS_LOADER = 165 static const String DARTJS_LOADER =
158 "http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"; 166 "http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js";
159 167
160 /** Emit the main .dart file. */ 168 /** Emit the main .dart file. */
161 void _emitMainDart(SourceFile file) { 169 void _emitMainDart(SourceFile file) {
162 var fileInfo = info[file.path]; 170 var fileInfo = info[file.path];
163 var contents = new MainPageEmitter(fileInfo).run(file.document); 171 var contents = new MainPageEmitter(fileInfo).run(file.document, _pathInfo);
164 output.add(new OutputFile(_pathInfo.outputLibraryPath(fileInfo), contents)); 172 output.add(new OutputFile(_pathInfo.outputLibraryPath(fileInfo), contents));
165 } 173 }
166 174
167 /** Generate an html file with the (trimmed down) main html page. */ 175 /** Generate an html file with the (trimmed down) main html page. */
168 void _emitMainHtml(SourceFile file) { 176 void _emitMainHtml(SourceFile file) {
169 var fileInfo = info[file.path]; 177 var fileInfo = info[file.path];
170 178
171 // Clear the body, we moved all of it 179 // Clear the body, we moved all of it
172 var document = file.document; 180 var document = file.document;
173 document.body.nodes.clear(); 181 document.body.nodes.clear();
(...skipping 18 matching lines...) Expand all
192 _addAutoGeneratedComment(file); 200 _addAutoGeneratedComment(file);
193 output.add(new OutputFile( 201 output.add(new OutputFile(
194 _pathInfo.fileInOutputDir('_${file.path.filename}.html'), 202 _pathInfo.fileInOutputDir('_${file.path.filename}.html'),
195 document.outerHTML)); 203 document.outerHTML));
196 } 204 }
197 205
198 /** Emits the Dart code for all components in the [file]. */ 206 /** Emits the Dart code for all components in the [file]. */
199 void _emitComponents(SourceFile file) { 207 void _emitComponents(SourceFile file) {
200 var fileInfo = info[file.path]; 208 var fileInfo = info[file.path];
201 for (var component in fileInfo.declaredComponents) { 209 for (var component in fileInfo.declaredComponents) {
202 var code = new WebComponentEmitter(fileInfo).run(component); 210 var code = new WebComponentEmitter(fileInfo).run(component, _pathInfo);
203 output.add(new OutputFile(_pathInfo.outputLibraryPath(component), code)); 211 output.add(new OutputFile(_pathInfo.outputLibraryPath(component), code));
204 } 212 }
205 } 213 }
206 214
207 /** Emit the wrapper .dart file for a component page. */ 215 /** Emit the wrapper .dart file for a component page. */
208 void _emitComponentDart(SourceFile file) { 216 void _emitComponentDart(SourceFile file) {
209 var fileInfo = info[file.path]; 217 var fileInfo = info[file.path];
210 // Reexport all components declared in the input file. 218 // Reexport all components declared in the input file.
211 var exports = fileInfo.declaredComponents.map( 219 var exports = fileInfo.declaredComponents.map(
212 (c) => PathInfo.relativePath(fileInfo, c)); 220 (c) => PathInfo.relativePath(fileInfo, c));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (doctype.tagName != 'html' || commentIndex != 1) { 268 if (doctype.tagName != 'html' || commentIndex != 1) {
261 messages.warning('file should start with <!DOCTYPE html> ' 269 messages.warning('file should start with <!DOCTYPE html> '
262 'to avoid the possibility of it being parsed in quirks mode in IE. ' 270 'to avoid the possibility of it being parsed in quirks mode in IE. '
263 'See http://www.w3.org/TR/html5-diff/#doctype', 271 'See http://www.w3.org/TR/html5-diff/#doctype',
264 doctype.span, file: file.path); 272 doctype.span, file: file.path);
265 } 273 }
266 } 274 }
267 document.nodes.insertAt(commentIndex, parseFragment( 275 document.nodes.insertAt(commentIndex, parseFragment(
268 '\n<!-- This file was auto-generated from template ${file.path}. -->\n')); 276 '\n<!-- This file was auto-generated from template ${file.path}. -->\n'));
269 } 277 }
OLDNEW
« no previous file with comments | « lib/src/codegen.dart ('k') | lib/src/directive_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698