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

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

Issue 12225039: Support for observable models, fixes #259 (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: Created 7 years, 10 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 unified diff | Download patch
« no previous file with comments | « lib/src/files.dart ('k') | lib/src/observable_transform.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 /** 5 /**
6 * Datatypes holding information extracted by the analyzer and used by later 6 * Datatypes holding information extracted by the analyzer and used by later
7 * phases of the compiler. 7 * phases of the compiler.
8 */ 8 */
9 library info; 9 library info;
10 10
11 import 'dart:collection' show SplayTreeMap, LinkedHashMap; 11 import 'dart:collection' show SplayTreeMap, LinkedHashMap;
12 import 'dart:uri'; 12 import 'dart:uri';
13 13
14 import 'package:html5lib/dom.dart'; 14 import 'package:html5lib/dom.dart';
15 import 'package:analyzer_experimental/src/generated/ast.dart';
15 import 'package:csslib/parser.dart' as css; 16 import 'package:csslib/parser.dart' as css;
16 import 'package:csslib/visitor.dart'; 17 import 'package:csslib/visitor.dart';
17 18
19 import 'dart_parser.dart' show DartCodeInfo;
18 import 'file_system/path.dart'; 20 import 'file_system/path.dart';
19 import 'files.dart'; 21 import 'files.dart';
20 import 'messages.dart'; 22 import 'messages.dart';
21 import 'utils.dart'; 23 import 'utils.dart';
22 24
23 /** Information about input, base, and output path locations. */ 25 /** Information about input, base, and output path locations. */
24 class PathInfo { 26 class PathInfo {
25 /** 27 /**
26 * Common prefix to all input paths that are read from the file system. The 28 * Common prefix to all input paths that are read from the file system. The
27 * output generated by the compiler will reflect the directory structure 29 * output generated by the compiler will reflect the directory structure
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * the form `<link rel="component" href="packages/...">`, so that you can 107 * the form `<link rel="component" href="packages/...">`, so that you can
106 * refer to components within the packages symlink. Regardless of whether an 108 * refer to components within the packages symlink. Regardless of whether an
107 * --out option was given to the compiler, we don't want to generate files 109 * --out option was given to the compiler, we don't want to generate files
108 * inside `packages/` for those components. Instead we will generate such 110 * inside `packages/` for those components. Instead we will generate such
109 * code in a special directory called `_from_packages/`. 111 * code in a special directory called `_from_packages/`.
110 */ 112 */
111 Path _rewritePackages(Path outputPath) { 113 Path _rewritePackages(Path outputPath) {
112 if (!outputPath.toString().contains('packages')) return outputPath; 114 if (!outputPath.toString().contains('packages')) return outputPath;
113 var segments = outputPath.segments().map( 115 var segments = outputPath.segments().map(
114 (segment) => segment == 'packages' ? '_from_packages' : segment); 116 (segment) => segment == 'packages' ? '_from_packages' : segment);
115 return new Path(segments.join('/')); 117 var rewrittenPath = segments.join('/');
118 if (outputPath.isAbsolute) {
119 // TODO(jmesserly): this is probably broken on Windows
120 // We need to switch to package:pathos
121 rewrittenPath = '/$rewrittenPath';
122 }
123 return new Path(rewrittenPath);
116 } 124 }
117 125
118 /** 126 /**
119 * Returns a relative path to import/export the output library represented by 127 * Returns a relative path to import/export the output library represented by
120 * [target] from the output library of [src]. In other words, a path to import 128 * [target] from the output library of [src]. In other words, a path to import
121 * or export `target.outputFilename` from `src.outputFilename`. 129 * or export `target.outputFilename` from `src.outputFilename`.
122 */ 130 */
123 Path relativePath(LibraryInfo src, LibraryInfo target) { 131 Path relativePath(LibraryInfo src, LibraryInfo target) {
124 var srcDir = src.inputPath.directoryPath; 132 var srcDir = src.inputPath.directoryPath;
125 var relDir = target.inputPath.directoryPath.relativeTo(srcDir); 133 var relDir = target.inputPath.directoryPath.relativeTo(srcDir);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 * can have .dart code provided by the user for top-level user scripts and 167 * can have .dart code provided by the user for top-level user scripts and
160 * component-level behavior code. This code can either be inlined in the HTML 168 * component-level behavior code. This code can either be inlined in the HTML
161 * file or included in a script tag with the "src" attribute. 169 * file or included in a script tag with the "src" attribute.
162 */ 170 */
163 abstract class LibraryInfo { 171 abstract class LibraryInfo {
164 172
165 /** Whether there is any code associated with the page/component. */ 173 /** Whether there is any code associated with the page/component. */
166 bool get codeAttached => inlinedCode != null || externalFile != null; 174 bool get codeAttached => inlinedCode != null || externalFile != null;
167 175
168 /** 176 /**
169 * The actual code, either inlined or from an external file, or `null` if none 177 * The actual inlined code. Use [userCode] if you want the code from this file
170 * was defined. 178 * or from an external file.
171 */ 179 */
172 DartCodeInfo userCode; 180 DartCodeInfo inlinedCode;
173
174 /** The inlined code, if any. */
175 String inlinedCode;
176 181
177 /** The name of the file sourced in a script tag, if any. */ 182 /** The name of the file sourced in a script tag, if any. */
178 Path externalFile; 183 Path externalFile;
179 184
180 /** Info asscociated with [externalFile], if any. */ 185 /** Info asscociated with [externalFile], if any. */
181 FileInfo externalCode; 186 FileInfo externalCode;
182 187
188 /**
189 * The inverse of [externalCode]. If this .dart file was imported via a script
190 * tag, this refers to the HTML file that imported it.
191 */
192 LibraryInfo htmlFile;
193
183 /** File where the top-level code was defined. */ 194 /** File where the top-level code was defined. */
184 Path get inputPath; 195 Path get inputPath;
185 196
186 /** Stylesheet with <style>...</style> */ 197 /** Stylesheet with <style>...</style> */
187 StringBuffer cssSource = new StringBuffer(); 198 StringBuffer cssSource = new StringBuffer();
188 199
189 /** Parsed cssSource. */ 200 /** Parsed cssSource. */
190 StyleSheet styleSheet; 201 StyleSheet styleSheet;
191 202
192 /** 203 /**
193 * Name of the file that will hold any generated Dart code for this library 204 * Name of the file that will hold any generated Dart code for this library
194 * unit. 205 * unit.
195 */ 206 */
196 String _getOutputFilename(NameMangler mangle); 207 String _getOutputFilename(NameMangler mangle);
197 208
209 /** This is used in transforming Dart code to track modified files. */
210 bool modified = false;
211
212 /**
213 * This is used in transforming Dart code to compute files that reference
214 * [modified] files.
215 */
216 List<FileInfo> referencedBy = [];
217
198 /** 218 /**
199 * Components used within this library unit. For [FileInfo] these are 219 * Components used within this library unit. For [FileInfo] these are
200 * components used directly in the page. For [ComponentInfo] these are 220 * components used directly in the page. For [ComponentInfo] these are
201 * components used within their shadowed template. 221 * components used within their shadowed template.
202 */ 222 */
203 final Map<ComponentInfo, bool> usedComponents = 223 final Map<ComponentInfo, bool> usedComponents =
204 new LinkedHashMap<ComponentInfo, bool>(); 224 new LinkedHashMap<ComponentInfo, bool>();
225
226 /**
227 * The actual code, either inlined or from an external file, or `null` if none
228 * was defined.
229 */
230 DartCodeInfo get userCode =>
231 externalCode != null ? externalCode.inlinedCode : inlinedCode;
205 } 232 }
206 233
207 /** Information extracted at the file-level. */ 234 /** Information extracted at the file-level. */
208 class FileInfo extends LibraryInfo { 235 class FileInfo extends LibraryInfo {
209 /** Relative path to this file from the compiler's base directory. */ 236 /** Relative path to this file from the compiler's base directory. */
210 final Path path; 237 final Path path;
211 238
212 /** 239 /**
213 * Whether this file should be treated as the entry point of the web app, i.e. 240 * Whether this file should be treated as the entry point of the web app, i.e.
214 * the file users navigate to in their browser. This will be true if this file 241 * the file users navigate to in their browser. This will be true if this file
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 652
626 /** 653 /**
627 * Specifies the action to take on a particular event. Some actions need to read 654 * Specifies the action to take on a particular event. Some actions need to read
628 * attributes from the DOM element that has the event listener (e.g. two way 655 * attributes from the DOM element that has the event listener (e.g. two way
629 * bindings do this). [elementVarName] stores a reference to this element. 656 * bindings do this). [elementVarName] stores a reference to this element.
630 * It is generated outside of the analyzer (in the emitter), so it is passed 657 * It is generated outside of the analyzer (in the emitter), so it is passed
631 * here as an argument. 658 * here as an argument.
632 */ 659 */
633 typedef String ActionDefinition(String elemVarName); 660 typedef String ActionDefinition(String elemVarName);
634 661
635 /** Information extracted from a source Dart file. */
636 class DartCodeInfo {
637 /** Library qualified identifier, if any. */
638 final String libraryName;
639
640 /** Library which the code is part-of, if any. */
641 final String partOf;
642
643 /** Declared imports, exports, and parts. */
644 final List<DartDirectiveInfo> directives;
645
646 /** The rest of the code. */
647 final String code;
648
649 DartCodeInfo(this.libraryName, this.partOf, this.directives, this.code);
650 }
651
652 /** Information about a single import/export/part directive. */
653 class DartDirectiveInfo {
654 /** Directive's label: import, export, or part. */
655 String label;
656
657 /** Referenced uri being imported, exported, or included by a part. */
658 String uri;
659
660 /** Prefix used for imports, if any. */
661 String prefix;
662
663 /** Hidden identifiers. */
664 List<String> hide;
665
666 /** Shown identifiers. */
667 List<String> show;
668
669 DartDirectiveInfo(this.label, this.uri, [this.prefix, this.hide, this.show]);
670 }
671
672 662
673 /** 663 /**
674 * Find ElementInfo that associated with a particular DOM node. 664 * Find ElementInfo that associated with a particular DOM node.
675 * Used by [ElementInfo.query]. 665 * Used by [ElementInfo.query].
676 */ 666 */
677 class _QueryInfo extends InfoVisitor { 667 class _QueryInfo extends InfoVisitor {
678 final String _tagName; 668 final String _tagName;
679 669
680 _QueryInfo(this._tagName); 670 _QueryInfo(this._tagName);
681 671
682 visitElementInfo(ElementInfo info) { 672 visitElementInfo(ElementInfo info) {
683 if (info.node.tagName == _tagName) { 673 if (info.node.tagName == _tagName) {
684 return info; 674 return info;
685 } 675 }
686 676
687 return super.visitElementInfo(info); 677 return super.visitElementInfo(info);
688 } 678 }
689 679
690 visitChildren(ElementInfo info) { 680 visitChildren(ElementInfo info) {
691 for (var child in info.children) { 681 for (var child in info.children) {
692 var result = visit(child); 682 var result = visit(child);
693 if (result != null) return result; 683 if (result != null) return result;
694 } 684 }
695 return null; 685 return null;
696 } 686 }
697 } 687 }
OLDNEW
« no previous file with comments | « lib/src/files.dart ('k') | lib/src/observable_transform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698