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

Side by Side Diff: lib/src/compiler/module_builder.dart

Issue 2006353002: Name loader functions. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 7 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/runtime/dart_sdk.js ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'package:path/path.dart' as path; 5 import 'package:path/path.dart' as path;
6 6
7 import '../js_ast/js_ast.dart'; 7 import '../js_ast/js_ast.dart';
8 import 'js_names.dart'; 8 import 'js_names.dart';
9 9
10 /// Base class for compiling ES6 modules into various ES5 module patterns. 10 /// Base class for compiling ES6 modules into various ES5 module patterns.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 assert(names != null); // export * not supported in legacy modules. 82 assert(names != null); // export * not supported in legacy modules.
83 for (var name in names) { 83 for (var name in names) {
84 statements 84 statements
85 .add(js.statement('#.# = #;', [exportsVar, name.name, name])); 85 .add(js.statement('#.# = #;', [exportsVar, name.name, name]));
86 } 86 }
87 } 87 }
88 } 88 }
89 89
90 var resultModule = 90 var resultModule =
91 js.call("function(#) { 'use strict'; #; }", [parameters, statements]); 91 js.call("function(#) { 'use strict'; #; }", [parameters, statements]);
92 var functionName =
93 'load__' + pathToJSIdentifier(module.name.replaceAll('.', '_'));
94 resultModule =
95 new NamedFunction(new Identifier(functionName), resultModule);
92 96
93 var moduleDef = js.statement("dart_library.library(#, #, #, #)", [ 97 var moduleDef = js.statement("dart_library.library(#, #, #, #)", [
94 js.string(module.name, "'"), 98 js.string(module.name, "'"),
95 new LiteralNull(), 99 new LiteralNull(),
96 js.commentExpression( 100 js.commentExpression(
97 "Imports", new ArrayInitializer(importNames, multiline: true)), 101 "Imports", new ArrayInitializer(importNames, multiline: true)),
98 resultModule 102 resultModule
99 ]); 103 ]);
100 return new Program(<ModuleItem>[moduleDef]); 104 return new Program(<ModuleItem>[moduleDef]);
101 } 105 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Ensure the identifier first character is not numeric and that the whole 178 // Ensure the identifier first character is not numeric and that the whole
175 // identifier is not a keyword. 179 // identifier is not a keyword.
176 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { 180 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) {
177 return '\$$result'; 181 return '\$$result';
178 } 182 }
179 return result; 183 return result;
180 } 184 }
181 185
182 // Invalid characters for identifiers, which would need to be escaped. 186 // Invalid characters for identifiers, which would need to be escaped.
183 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); 187 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]');
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698