This repository was archived by the owner on May 22, 2025. It is now read-only.
File tree 4 files changed +26
-4
lines changed 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -775,6 +775,8 @@ class Annotator extends ClosureRewriter {
775
775
// If it has a symbol, it's actually a regular declared property.
776
776
if ( ! quotedPropSym ) return false ;
777
777
const propName = ( eae . argumentExpression as ts . StringLiteral ) . text ;
778
+ // Properties containing non-JS identifier names must not be unquoted.
779
+ if ( ! isValidClosurePropertyName ( propName ) ) return false ;
778
780
this . writeNode ( eae . expression ) ;
779
781
this . emit ( `.${ propName } ` ) ;
780
782
return true ;
Original file line number Diff line number Diff line change 1
- goog . module ( 'test_files.quote_props.quote' ) ; var module = module || { id : 'test_files/quote_props/quote.js' } ;
1
+ goog . module ( 'test_files.quote_props.quote' ) ; var module = module || { id : 'test_files/quote_props/quote.js' } ; /**
2
+ * @fileoverview added by tsickle
3
+ * @suppress {checkTypes} checked by tsc
4
+ */
5
+
2
6
/**
3
7
* @record
4
8
*/
@@ -14,8 +18,10 @@ quoted['hello'] = 1;
14
18
function QuotedMixed ( ) { }
15
19
/** @type {number } */
16
20
QuotedMixed . prototype . foo ;
17
- let /** @type {!QuotedMixed } */ quotedMixed = { foo : 1 } ;
21
+ let /** @type {!QuotedMixed } */ quotedMixed = { foo : 1 , 'invalid-identifier' : 2 } ;
18
22
console . log ( quotedMixed . foo ) ;
19
23
quotedMixed . foo = 1 ;
20
24
// Should be converted to non-quoted access.
21
25
quotedMixed . foo = 1 ;
26
+ // Must not be converted to non-quoted access, as it's not valid JS.
27
+ quotedMixed [ 'invalid-identifier' ] = 1 ;
Original file line number Diff line number Diff line change @@ -15,10 +15,13 @@ interface QuotedMixed extends Quoted {
15
15
// It's unclear whether it's the right thing to do, user code might
16
16
// access this field in a mixed fashion.
17
17
foo : number ;
18
+ 'invalid-identifier' : number ;
18
19
}
19
- let quotedMixed : QuotedMixed = { foo : 1 } ;
20
+ let quotedMixed : QuotedMixed = { foo : 1 , 'invalid-identifier' : 2 } ;
20
21
console . log ( quotedMixed . foo ) ;
21
22
22
23
quotedMixed . foo = 1 ;
23
24
// Should be converted to non-quoted access.
24
25
quotedMixed [ 'foo' ] = 1 ;
26
+ // Must not be converted to non-quoted access, as it's not valid JS.
27
+ quotedMixed [ 'invalid-identifier' ] = 1 ;
Original file line number Diff line number Diff line change 1
1
Warning at test_files / quote_props / quote . ts :9 :13 : Quoted has a string index type but is accessed using dotted access . Quoting the access .
2
2
Warning at test_files / quote_props / quote . ts :10 :1 : Quoted has a string index type but is accessed using dotted access . Quoting the access .
3
3
= ===
4
+ /**
5
+ * @fileoverview added by tsickle
6
+ * @suppress {checkTypes} checked by tsc
7
+ */
8
+
4
9
// silence warnings about redeclaring vars.
5
10
export { } ;
6
11
/**
@@ -27,17 +32,23 @@ quoted['hello'] = 1;
27
32
function QuotedMixed ( ) { }
28
33
/** @type {number } */
29
34
QuotedMixed . prototype . foo ;
35
+ /* TODO: handle strange member:
36
+ 'invalid-identifier': number;
37
+ */
30
38
31
39
32
40
interface QuotedMixed extends Quoted {
33
41
// Assume that foo should be renamed, as it is explicitly declared.
34
42
// It's unclear whether it's the right thing to do, user code might
35
43
// access this field in a mixed fashion.
36
44
foo : number;
45
+ 'invalid-identifier' : number ;
37
46
}
38
- let /** @type {!QuotedMixed } */ quotedMixed : QuotedMixed = { foo : 1 } ;
47
+ let /** @type {!QuotedMixed } */ quotedMixed : QuotedMixed = { foo : 1 , 'invalid-identifier' : 2 } ;
39
48
console . log ( quotedMixed . foo ) ;
40
49
41
50
quotedMixed . foo = 1 ;
42
51
// Should be converted to non-quoted access.
43
52
quotedMixed . foo = 1 ;
53
+ // Must not be converted to non-quoted access, as it's not valid JS.
54
+ quotedMixed [ 'invalid-identifier' ] = 1 ;
You can’t perform that action at this time.
0 commit comments