| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Logic to validate that developers are correctly using Polymer constructs. | 5 /// Logic to validate that developers are correctly using Polymer constructs. |
| 6 /// This is mainly used to produce warnings for feedback in the editor. | 6 /// This is mainly used to produce warnings for feedback in the editor. |
| 7 library polymer.src.build.linter; | 7 library polymer.src.build.linter; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (!_validateCustomAttributeName(attr, attrsSpan)) break; | 237 if (!_validateCustomAttributeName(attr, attrsSpan)) break; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 var oldValue = _inPolymerElement; | 241 var oldValue = _inPolymerElement; |
| 242 _inPolymerElement = true; | 242 _inPolymerElement = true; |
| 243 super.visitElement(node); | 243 super.visitElement(node); |
| 244 _inPolymerElement = oldValue; | 244 _inPolymerElement = oldValue; |
| 245 } | 245 } |
| 246 | 246 |
| 247 /// Produces warnings for malformed script tags. In html5 leaving off type= is | 247 /// Checks for multiple Dart script tags in the same page, which is invalid. |
| 248 /// fine, but it defaults to text/javascript. Because this might be a common | |
| 249 /// error, we warn about it when src file ends in .dart, but the type is | |
| 250 /// incorrect, or when users write code in an inline script tag of a custom | |
| 251 /// element. | |
| 252 /// | |
| 253 /// The hope is that these cases shouldn't break existing valid code, but that | |
| 254 /// they'll help Polymer authors avoid having their Dart code accidentally | |
| 255 /// interpreted as JavaScript by the browser. | |
| 256 void _validateScriptElement(Element node) { | 248 void _validateScriptElement(Element node) { |
| 257 var scriptType = node.attributes['type']; | 249 var scriptType = node.attributes['type']; |
| 258 var isDart = scriptType == 'application/dart'; | 250 var isDart = scriptType == 'application/dart'; |
| 259 var src = node.attributes['src']; | 251 var src = node.attributes['src']; |
| 260 | 252 |
| 261 if (scriptType == null) { | 253 if (isDart) { |
| 262 if (src == null && _inPolymerElement) { | |
| 263 // TODO(sigmund): revisit this check once we start interop with polymer | |
| 264 // elements written in JS. Maybe we need to inspect the contents of the | |
| 265 // script to find whether there is an import or something that indicates | |
| 266 // that the code is indeed using Dart. | |
| 267 _logger.warning('script tag in polymer element with no type will ' | |
| 268 'be treated as JavaScript. Did you forget type="application/dart"?', | |
| 269 span: node.sourceSpan); | |
| 270 } | |
| 271 } else if (isDart) { | |
| 272 if (_dartTagSeen) { | 254 if (_dartTagSeen) { |
| 273 _logger.warning('Only one "application/dart" script tag per document ' | 255 _logger.warning('Only one "application/dart" script tag per document ' |
| 274 'is allowed.', span: node.sourceSpan); | 256 'is allowed.', span: node.sourceSpan); |
| 275 } | 257 } |
| 276 _dartTagSeen = true; | 258 _dartTagSeen = true; |
| 277 } | 259 } |
| 278 | 260 |
| 279 if (src == null) return; | 261 if (src == null) return; |
| 280 | 262 |
| 281 if (src == 'packages/polymer/boot.js') { | 263 if (src == 'packages/polymer/boot.js') { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 'Make sure the script tag is placed after all HTML imports.'; | 415 'Make sure the script tag is placed after all HTML imports.'; |
| 434 | 416 |
| 435 const String BOOT_JS_DEPRECATED = | 417 const String BOOT_JS_DEPRECATED = |
| 436 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' | 418 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' |
| 437 'application by calling "initPolymer()" in your main. If you don\'t have a ' | 419 'application by calling "initPolymer()" in your main. If you don\'t have a ' |
| 438 'main, then you can include our generic main by adding the following ' | 420 'main, then you can include our generic main by adding the following ' |
| 439 'script tag to your page: \'<script type="application/dart">export ' | 421 'script tag to your page: \'<script type="application/dart">export ' |
| 440 '"package:polymer/init.dart";</script>\'. Additionally you need to ' | 422 '"package:polymer/init.dart";</script>\'. Additionally you need to ' |
| 441 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' | 423 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' |
| 442 'too. Make sure these script tags come after all HTML imports.'; | 424 'too. Make sure these script tags come after all HTML imports.'; |
| OLD | NEW |