fix(ivy): wrap "inputs" and "outputs" keys if they contain unsafe characters (#28919)

Prior to this change, keys in "inputs" and "outputs" objects generated by compiler were not checked against unsafe characters. As a result, in some cases the generated code was throwing JS error. Now we check whether a given key contains any unsafe chars and wrap it in quotes if needed.

PR Close #28919
This commit is contained in:
Andrew Kushnir
2019-02-21 21:33:05 -08:00
parent 78adcfe0ee
commit aa57bdbf90
2 changed files with 34 additions and 1 deletions

View File

@ -2148,6 +2148,28 @@ describe('ngtsc behavioral tests', () => {
});
});
it('should wrap "inputs" and "outputs" keys if they contain unsafe characters', () => {
env.tsconfig({});
env.write(`test.ts`, `
import {Directive} from '@angular/core';
@Directive({
selector: '[somedir]',
inputs: ['input-track-type', 'inputTrackName'],
outputs: ['output-track-type', 'outputTrackName']
})
export class SomeDir {}
`);
env.driveMain();
const jsContents = env.getContents('test.js');
const inputsAndOutputs = `
inputs: { "input-track-type": "input-track-type", inputTrackName: "inputTrackName" },
outputs: { "output-track-type": "output-track-type", outputTrackName: "outputTrackName" }
`;
expect(trim(jsContents)).toContain(trim(inputsAndOutputs));
});
it('should compile programs with typeRoots', () => {
// Write out a custom tsconfig.json that includes 'typeRoots' and 'files'. 'files' is necessary
// because otherwise TS picks up the testTypeRoot/test/index.d.ts file into the program