OLD | NEW |
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 * Part of the template compilation that concerns with extracting information | 6 * Part of the template compilation that concerns with extracting information |
7 * from the HTML parse tree. | 7 * from the HTML parse tree. |
8 */ | 8 */ |
9 library analyzer; | 9 library analyzer; |
10 | 10 |
11 import 'package:html5lib/dom.dart'; | 11 import 'package:html5lib/dom.dart'; |
12 import 'package:html5lib/dom_parsing.dart'; | 12 import 'package:html5lib/dom_parsing.dart'; |
13 | 13 |
14 import 'directive_parser.dart' show parseDartCode; | 14 import 'dart_parser.dart'; |
15 import 'file_system/path.dart'; | 15 import 'file_system/path.dart'; |
16 import 'files.dart'; | 16 import 'files.dart'; |
17 import 'html5_utils.dart'; | 17 import 'html5_utils.dart'; |
18 import 'info.dart'; | 18 import 'info.dart'; |
19 import 'messages.dart'; | 19 import 'messages.dart'; |
20 import 'utils.dart'; | 20 import 'utils.dart'; |
21 | 21 |
22 /** | 22 /** |
23 * Finds custom elements in this file and the list of referenced files with | 23 * Finds custom elements in this file and the list of referenced files with |
24 * component declarations. This is the first pass of analysis on a file. | 24 * component declarations. This is the first pass of analysis on a file. |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 705 } |
706 | 706 |
707 /** | 707 /** |
708 * Stores a direct reference in [info] to a dart source file that was loaded | 708 * Stores a direct reference in [info] to a dart source file that was loaded |
709 * in a script tag with the 'src' attribute. | 709 * in a script tag with the 'src' attribute. |
710 */ | 710 */ |
711 void _attachExtenalScript(LibraryInfo info, Map<Path, FileInfo> files) { | 711 void _attachExtenalScript(LibraryInfo info, Map<Path, FileInfo> files) { |
712 var path = info.externalFile; | 712 var path = info.externalFile; |
713 if (path != null) { | 713 if (path != null) { |
714 info.externalCode = files[path]; | 714 info.externalCode = files[path]; |
715 info.userCode = info.externalCode.userCode; | 715 info.externalCode.htmlFile = info; |
716 } | 716 } |
717 } | 717 } |
718 | 718 |
719 /** Adds a component's tag name to the names in scope for [fileInfo]. */ | 719 /** Adds a component's tag name to the names in scope for [fileInfo]. */ |
720 void _addComponent(FileInfo fileInfo, ComponentInfo componentInfo) { | 720 void _addComponent(FileInfo fileInfo, ComponentInfo componentInfo) { |
721 var existing = fileInfo.components[componentInfo.tagName]; | 721 var existing = fileInfo.components[componentInfo.tagName]; |
722 if (existing != null) { | 722 if (existing != null) { |
723 if (existing == componentInfo) { | 723 if (existing == componentInfo) { |
724 // This is the same exact component as the existing one. | 724 // This is the same exact component as the existing one. |
725 return; | 725 return; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 assert(node.nodes.length == 1); | 946 assert(node.nodes.length == 1); |
947 Text text = node.nodes[0]; | 947 Text text = node.nodes[0]; |
948 | 948 |
949 if (_currentInfo.codeAttached) { | 949 if (_currentInfo.codeAttached) { |
950 _tooManyScriptsError(node); | 950 _tooManyScriptsError(node); |
951 } else if (_currentInfo == _fileInfo && !_fileInfo.isEntryPoint) { | 951 } else if (_currentInfo == _fileInfo && !_fileInfo.isEntryPoint) { |
952 _messages.warning('top-level dart code is ignored on ' | 952 _messages.warning('top-level dart code is ignored on ' |
953 ' HTML pages that define components, but are not the entry HTML ' | 953 ' HTML pages that define components, but are not the entry HTML ' |
954 'file.', node.sourceSpan, file: _fileInfo.path); | 954 'file.', node.sourceSpan, file: _fileInfo.path); |
955 } else { | 955 } else { |
956 _currentInfo.inlinedCode = text.value; | 956 var path = _currentInfo.inputPath; |
957 _currentInfo.userCode = parseDartCode(text.value, | 957 _currentInfo.inlinedCode = parseDartCode(path, text.value, _messages); |
958 _currentInfo.inputPath, messages:_messages); | |
959 if (_currentInfo.userCode.partOf != null) { | 958 if (_currentInfo.userCode.partOf != null) { |
960 _messages.error('expected a library, not a part.', | 959 _messages.error('expected a library, not a part.', |
961 node.sourceSpan, file: _fileInfo.path); | 960 node.sourceSpan, file: _fileInfo.path); |
962 } | 961 } |
963 } | 962 } |
964 } | 963 } |
965 | 964 |
966 void _tooManyScriptsError(Node node) { | 965 void _tooManyScriptsError(Node node) { |
967 var location = _currentInfo is ComponentInfo ? | 966 var location = _currentInfo is ComponentInfo ? |
968 'a custom element declaration' : 'the top-level HTML page'; | 967 'a custom element declaration' : 'the top-level HTML page'; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 if (start == null) moveNext(); | 1030 if (start == null) moveNext(); |
1032 if (start < length) { | 1031 if (start < length) { |
1033 do { | 1032 do { |
1034 bindings.add(binding); | 1033 bindings.add(binding); |
1035 content.add(textContent); | 1034 content.add(textContent); |
1036 } while (moveNext()); | 1035 } while (moveNext()); |
1037 } | 1036 } |
1038 content.add(textContent); | 1037 content.add(textContent); |
1039 } | 1038 } |
1040 } | 1039 } |
OLD | NEW |