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

Side by Side Diff: lib/src/transformer/utils.dart

Issue 580283004: Add JsInitializerGenerator (Closed) Base URL: https://github.com/dart-lang/js-interop.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « lib/src/transformer/library_transformer.dart ('k') | test/transformer/all_tests.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library js.transformer.utils; 5 library js.transformer.utils;
6 6
7 import 'package:analyzer/analyzer.dart';
7 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/analyzer.dart'; 9 import 'package:barback/barback.dart';
9 import 'package:js/src/metadata.dart'; 10 import 'package:js/src/metadata.dart';
11 import 'package:path/path.dart' as path;
10 import 'package:quiver/iterables.dart' show max; 12 import 'package:quiver/iterables.dart' show max;
11 13
12 const String INITIALIZER_SUFFIX = "__init_js__.dart"; 14 const String DART_INITIALIZER_SUFFIX = "__init_js__.dart";
15 const String JS_INITIALIZER_SUFFIX = "__init_js__.js";
13 16
14 JsProxy getProxyAnnotation(ClassElement interface, ClassElement jsProxyClass) { 17 JsProxy getProxyAnnotation(ClassElement interface, ClassElement jsProxyClass) {
15 var node = interface.node; 18 var node = interface.node;
16 for (Annotation a in node.metadata) { 19 for (Annotation a in node.metadata) {
17 var e = a.element; 20 var e = a.element;
18 if (e is ConstructorElement && e.type.returnType == jsProxyClass.type) { 21 if (e is ConstructorElement && e.type.returnType == jsProxyClass.type) {
19 bool global; 22 bool global;
20 String constructor; 23 String constructor;
21 for (Expression e in a.arguments.arguments) { 24 for (Expression e in a.arguments.arguments) {
22 if (e is NamedExpression) { 25 if (e is NamedExpression) {
(...skipping 23 matching lines...) Expand all
46 insertImportOffset = libraryDirective.end; 49 insertImportOffset = libraryDirective.end;
47 } 50 }
48 } else { 51 } else {
49 insertImportOffset = max(library.definingCompilationUnit.node.directives 52 insertImportOffset = max(library.definingCompilationUnit.node.directives
50 .where((d) => d is ImportDirective) 53 .where((d) => d is ImportDirective)
51 .map((ImportDirective e) => e.end)); 54 .map((ImportDirective e) => e.end));
52 if (insertImportOffset == null) insertImportOffset = 0; 55 if (insertImportOffset == null) insertImportOffset = 0;
53 } 56 }
54 return insertImportOffset; 57 return insertImportOffset;
55 } 58 }
59
60
61 final illegalIdRegex = new RegExp(r'[^a-zA-Z0-9_]');
62
63 String assetIdToPrefix(AssetId id) =>
64 '_js__${id.package}__${id.path.replaceAll(illegalIdRegex, '_')}';
65
66 String assetIdToJsExportCall(AssetId id) =>
67 '_export_${id.path.replaceAll(illegalIdRegex, '_')}(dart);';
68
69 // TODO(justinfagnani): put this in code_transformers ?
70 String getImportUri(AssetId importId, AssetId from) {
71 if (importId.path.startsWith('lib/')) {
72 // we support package imports
73 return "package:${importId.package}/${importId.path.substring(4)}";
74 } else if (importId.package == from.package) {
75 // we can support relative imports
76 return path.relative(importId.path, from: path.dirname(from.path));
77 }
78 // cannot import
79 return null;
80 }
OLDNEW
« no previous file with comments | « lib/src/transformer/library_transformer.dart ('k') | test/transformer/all_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698