| 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 'dart:coreimpl'; | 11 import 'dart:coreimpl'; |
| 12 import 'package:html5lib/dom.dart'; | 12 import 'package:html5lib/dom.dart'; |
| 13 import 'package:html5lib/dom_parsing.dart'; | 13 import 'package:html5lib/dom_parsing.dart'; |
| 14 | 14 |
| 15 import 'directive_parser.dart' show parseDartCode; |
| 15 import 'file_system/path.dart'; | 16 import 'file_system/path.dart'; |
| 16 import 'files.dart'; | 17 import 'files.dart'; |
| 17 import 'info.dart'; | 18 import 'info.dart'; |
| 18 import 'messages.dart'; | 19 import 'messages.dart'; |
| 19 import 'utils.dart'; | 20 import 'utils.dart'; |
| 20 | 21 |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * Finds custom elements in this file and the list of referenced files with | 24 * 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. | 25 * component declarations. This is the first pass of analysis on a file. |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 Text text = node.nodes[0]; | 467 Text text = node.nodes[0]; |
| 467 | 468 |
| 468 if (_currentInfo.codeAttached) { | 469 if (_currentInfo.codeAttached) { |
| 469 _tooManyScriptsError(node); | 470 _tooManyScriptsError(node); |
| 470 } else if (_currentInfo == _fileInfo && !_fileInfo.isEntryPoint) { | 471 } else if (_currentInfo == _fileInfo && !_fileInfo.isEntryPoint) { |
| 471 messages.warning('top-level dart code is ignored on ' | 472 messages.warning('top-level dart code is ignored on ' |
| 472 ' HTML pages that define components, but are not the entry HTML ' | 473 ' HTML pages that define components, but are not the entry HTML ' |
| 473 'file.', node.span, file: _fileInfo.path); | 474 'file.', node.span, file: _fileInfo.path); |
| 474 } else { | 475 } else { |
| 475 _currentInfo.inlinedCode = text.value; | 476 _currentInfo.inlinedCode = text.value; |
| 477 _currentInfo.userCode = parseDartCode(text.value, |
| 478 _currentInfo.inputPath, messages); |
| 479 if (_currentInfo.userCode.partOf != null) { |
| 480 messages.error('expected a library, not a part.', |
| 481 node.span, file: _fileInfo.path); |
| 482 } |
| 476 } | 483 } |
| 477 } | 484 } |
| 478 | 485 |
| 479 void _tooManyScriptsError(Node node) { | 486 void _tooManyScriptsError(Node node) { |
| 480 var location = _currentInfo is ComponentInfo ? | 487 var location = _currentInfo is ComponentInfo ? |
| 481 'a custom element declaration' : 'the top-level HTML page'; | 488 'a custom element declaration' : 'the top-level HTML page'; |
| 482 | 489 |
| 483 messages.error('there should be only one dart script tag in $location.', | 490 messages.error('there should be only one dart script tag in $location.', |
| 484 node.span, file: _fileInfo.path); | 491 node.span, file: _fileInfo.path); |
| 485 } | 492 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 513 } | 520 } |
| 514 | 521 |
| 515 /** | 522 /** |
| 516 * Stores a direct reference in [info] to a dart source file that was loaded in | 523 * Stores a direct reference in [info] to a dart source file that was loaded in |
| 517 * a `<script src="">` tag. | 524 * a `<script src="">` tag. |
| 518 */ | 525 */ |
| 519 void _attachExtenalScript(LibraryInfo info, Map<Path, FileInfo> files) { | 526 void _attachExtenalScript(LibraryInfo info, Map<Path, FileInfo> files) { |
| 520 var path = info.externalFile; | 527 var path = info.externalFile; |
| 521 if (path != null) { | 528 if (path != null) { |
| 522 info.externalCode = files[path]; | 529 info.externalCode = files[path]; |
| 530 info.userCode = info.externalCode.userCode; |
| 523 } | 531 } |
| 524 } | 532 } |
| 525 | 533 |
| 526 /** Adds a component's tag name to the names in scope for [fileInfo]. */ | 534 /** Adds a component's tag name to the names in scope for [fileInfo]. */ |
| 527 void _addComponent(FileInfo fileInfo, ComponentInfo componentInfo) { | 535 void _addComponent(FileInfo fileInfo, ComponentInfo componentInfo) { |
| 528 var existing = fileInfo.components[componentInfo.tagName]; | 536 var existing = fileInfo.components[componentInfo.tagName]; |
| 529 if (existing != null) { | 537 if (existing != null) { |
| 530 if (existing.declaringFile == fileInfo && | 538 if (existing.declaringFile == fileInfo && |
| 531 componentInfo.declaringFile != fileInfo) { | 539 componentInfo.declaringFile != fileInfo) { |
| 532 // Components declared in [fileInfo] are allowed to shadow component | 540 // Components declared in [fileInfo] are allowed to shadow component |
| (...skipping 22 matching lines...) Expand all Loading... |
| 555 file: existing.declaringFile.path); | 563 file: existing.declaringFile.path); |
| 556 messages.error('imported duplicate custom element definitions ' | 564 messages.error('imported duplicate custom element definitions ' |
| 557 'for "${componentInfo.tagName}" (second location).', | 565 'for "${componentInfo.tagName}" (second location).', |
| 558 componentInfo.element.span, | 566 componentInfo.element.span, |
| 559 file: componentInfo.declaringFile.path); | 567 file: componentInfo.declaringFile.path); |
| 560 } | 568 } |
| 561 } else { | 569 } else { |
| 562 fileInfo.components[componentInfo.tagName] = componentInfo; | 570 fileInfo.components[componentInfo.tagName] = componentInfo; |
| 563 } | 571 } |
| 564 } | 572 } |
| OLD | NEW |