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

Unified Diff: pkg/polymer/lib/src/loader.dart

Issue 41983004: Now that Dartium requires a single script tag, it no longer tags inline script (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/loader.dart
diff --git a/pkg/polymer/lib/src/loader.dart b/pkg/polymer/lib/src/loader.dart
index 31661fc2f4e0a0f8843ca3c6c50948daa0278588..eeb7555b710b3f7c763ba0c91541b2dc089c37e6 100644
--- a/pkg/polymer/lib/src/loader.dart
+++ b/pkg/polymer/lib/src/loader.dart
@@ -112,22 +112,18 @@ List<String> _discoverScripts(Document doc, String baseUri,
if (seen.contains(doc)) return scripts;
seen.add(doc);
- var inlinedScriptCount = 0;
+ bool scriptSeen = false;
for (var node in doc.queryAll('script,link[rel="import"]')) {
if (node is LinkElement) {
_discoverScripts(node.import, node.href, seen, scripts);
} else if (node is ScriptElement && node.type == 'application/dart') {
- var url = node.src;
- if (url != '') {
- // TODO(sigmund): consider either normalizing package: urls or add a
- // warning to let users know about cannonicalization issues.
- scripts.add(url);
+ if (!scriptSeen) {
+ var url = node.src;
+ scripts.add(url == '' ? baseUri : url);
+ scriptSeen = true;
} else {
- // We generate a unique identifier for inlined scripts which we later
- // translate to the unique identifiers used by Dartium. Dartium uses
- // line/column number information which we can't compute here.
- scripts.add('$baseUri:$inlinedScriptCount');
- inlinedScriptCount++;
+ print('warning: more than one Dart script tag in $baseUri. Dartium '
+ 'currently only allows a single Dart script tag per document.');
}
}
}
@@ -144,41 +140,6 @@ final _rootUri = currentMirrorSystem().isolate.rootLibrary.uri;
final String _packageRoot =
'${path.dirname(Uri.parse(window.location.href).path)}/packages/';
-/** Regex that matches urls used to represent inlined scripts. */
-final RegExp _inlineScriptRegExp = new RegExp('\(.*\.html.*\):\([0-9]\+\)');
-
-/**
- * Map URLs fabricated by polymer to URLs fabricated by Dartium to represent
- * inlined scripts. Polymer uses baseUri:script#, Dartium uses baseUri:line#
- */
-// TODO(sigmund): figure out if we can generate the same URL and expose it.
-final Map<Uri, List<Uri>> _inlinedScriptMapping = () {
- var map = {};
- for (var uri in _libs.keys) {
- var uriString = uri.toString();
- var match = _inlineScriptRegExp.firstMatch(uriString);
- if (match == null) continue;
- var baseUri = Uri.parse(match.group(1));
- if (map[baseUri] == null) map[baseUri] = [];
- map[baseUri].add(uri);
- }
- return map;
-}();
-
-/** Returns a new Uri that replaces [path] in [uri]. */
-Uri _replacePath(Uri uri, String path) {
- return new Uri(scheme: uri.scheme, host: uri.host, port: uri.port,
- path: path, query: uri.query, fragment: uri.fragment);
-}
-
-/** Returns the Uri in [href] without query parameters or fragments. */
-String _baseUri(String href) {
- var uri = Uri.parse(window.location.href);
- var trimUri = new Uri(scheme: uri.scheme, host: uri.host,
- port: uri.port, path: uri.path);
- return trimUri.toString();
-}
-
/**
* Reads the library at [uriString] (which can be an absolute URI or a relative
* URI from the root library), and:
@@ -191,25 +152,16 @@ String _baseUri(String href) {
*/
void _loadLibrary(String uriString) {
var uri = _rootUri.resolve(uriString);
- var lib;
- var match = _inlineScriptRegExp.firstMatch(uriString);
- if (match != null) {
- var baseUri = Uri.parse(match.group(1));
- var list = _inlinedScriptMapping[baseUri];
- var pos = int.parse(match.group(2), onError: (_) => -1);
- if (list != null && pos >= 0 && pos < list.length && list[pos] != null) {
- lib = _libs[list[pos]];
- }
- } else if (uri.path.startsWith(_packageRoot)) {
+ var lib = _libs[uri];
+ if (uri.path.startsWith(_packageRoot) && uri.path.endsWith('.dart')) {
var packageUri =
Uri.parse('package:${uri.path.substring(_packageRoot.length)}');
- lib = _libs[packageUri];
- if (lib == null) {
- lib = _libs[uri];
+ var canonicalLib = _libs[packageUri];
+ if (canonicalLib != null) {
+ lib = canonicalLib;
}
- } else {
- lib = _libs[uri];
}
+
if (lib == null) {
print('warning: $uri library not found');
return;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698