@@ -196,45 +196,59 @@ public void testNoCallerLocationDefaultParameter() {
196
196
}
197
197
198
198
@ Test
199
- public void testCallerLocationIsSpecified () {
199
+ public void testGoogCallerLocationDefinitionInBaseJsDoesNotError () {
200
+ String baseJsSource =
201
+ lines (
202
+ "var goog = goog || {};" , //
203
+ "goog.callerLocation = function() {};" );
204
+ SourceFile baseJs = SourceFile .fromCode ("javascript/closure/base.js" , baseJsSource );
205
+ // this code is only allowed in base.js
206
+ test (srcs (baseJs ), expected (baseJs ));
207
+ }
208
+
209
+ @ Test
210
+ public void testNoRewritingIfCallerLocationIsSpecified () {
200
211
enableTypeCheck ();
201
212
enableParseTypeInfo ();
213
+
214
+ String baseJsSource =
215
+ lines (
216
+ "var goog = goog || {};" , //
217
+ "goog.callerLocation = function() {};" );
218
+ SourceFile baseJs = SourceFile .fromCode ("javascript/closure/base.js" , baseJsSource );
219
+
202
220
// no rewriting if CodeLocation is provided as an argument
203
- testSame (
221
+ String codeLocationProvided =
204
222
lines (
205
- "var goog = goog || {};" ,
206
- "goog.callerLocation = function() {};" ,
207
223
"function signal(here = goog.callerLocation()) {}" ,
208
- "const mySignal = signal('path/to/file.ts:25');" ));
224
+ "const mySignal = signal('path/to/file.ts:25');" );
225
+ SourceFile testJs = SourceFile .fromCode ("codeLocationProvided.js" , codeLocationProvided );
226
+ testSame (srcs (baseJs , testJs ));
209
227
210
- testSame (
228
+ String codeLocationProvided2 =
211
229
lines (
212
- "var goog = goog || {};" ,
213
- "goog.callerLocation = function() {};" ,
214
230
"function signal(val, here = goog.callerLocation()) {}" ,
215
- "const mySignal = signal(0, xid('path/to/file.ts:25'));" ));
231
+ "const mySignal = signal(0, xid('path/to/file.ts:25'));" );
232
+ SourceFile testJs2 = SourceFile .fromCode ("codeLocationProvided2.js" , codeLocationProvided2 );
233
+ testSame (srcs (baseJs , testJs2 ));
216
234
217
- testSame (
235
+ String codeLocationProvided3 =
218
236
lines (
219
- "var goog = goog || {};" ,
220
- "goog.callerLocation = function() {};" ,
221
237
"function signal(val, here = goog.callerLocation()) {}" ,
222
238
"const mySignal = signal(" ,
223
239
" () => foo() % 2 === 0," ,
224
240
" xid('path/to/file.ts:25')," ,
225
- ");" ));
226
- }
241
+ ");" );
242
+ SourceFile testJs3 = SourceFile .fromCode ("codeLocationProvided3.js" , codeLocationProvided3 );
243
+ testSame (srcs (baseJs , testJs3 ));
227
244
228
- @ Test
229
- public void testCallerLocationIsSpecified_withNonStringArgument () {
230
- enableTypeCheck ();
231
245
// no rewriting if CodeLocation is provided as an argument, regardless of the type of the arg
232
- testSame (
246
+ String codeLocationProvided4 =
233
247
lines (
234
- "var goog = goog || {};" ,
235
- "goog.callerLocation = function() {};" ,
236
248
"function signal(here = goog.callerLocation()) {}" , //
237
- "const mySignal = signal(foo());" ));
249
+ "const mySignal = signal(foo());" );
250
+ SourceFile testJs4 = SourceFile .fromCode ("codeLocationProvided4.js" , codeLocationProvided4 );
251
+ testSame (srcs (baseJs , testJs4 ));
238
252
}
239
253
240
254
@ Test
0 commit comments