Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsii): switch to disable reserved words warnings #1076

Merged
merged 8 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii && jsii-rosetta --compile",
"build": "jsii --disable-reserved-words-warnings && jsii-rosetta --compile",
"watch": "jsii -w",
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
Expand Down
7 changes: 6 additions & 1 deletion packages/jsii/bin/jsii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { VERSION } from '../lib/version';
type: 'boolean',
desc: 'Treat warnings as errors'
})
.option('disable-reserved-words-warnings', {
type: 'boolean',
desc: 'Do not emit warnings for symbols that are reserved words in one of the supported languages',
})
.help()
.version(`${VERSION}, typescript ${require('typescript/package.json').version}`)
.argv;
Expand All @@ -41,7 +45,8 @@ import { VERSION } from '../lib/version';
projectInfo,
watch: argv.watch,
projectReferences: argv['project-references'],
failOnWarnings: argv['fail-on-warnings']
failOnWarnings: argv['fail-on-warnings'],
reservedWordsWarningsDisabled: argv['disable-reserved-words-warnings']
});

return { projectRoot, emitResult: await compiler.emit() };
Expand Down
18 changes: 17 additions & 1 deletion packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ const sortJson = require('sort-json');

const LOG = log4js.getLogger('jsii/assembler');

export interface AssemblerOptions {
/**
* Do not emit warnings for reserved words.
* @default false (warnings are emitted)
*/
readonly reservedWordsWarningsDisabled?: boolean;
}

/**
* The JSII Assembler consumes a ``ts.Program`` instance and emits a JSII assembly.
*/
export class Assembler implements Emitter {
private _diagnostics = new Array<Diagnostic>();
private _deferred = new Array<DeferredRecord>();
private _types: { [fqn: string]: spec.Type } = {};
private readonly _reservedWordsWarningsDisabled: boolean = false;

/**
* @param projectInfo information about the package being assembled
Expand All @@ -38,7 +47,11 @@ export class Assembler implements Emitter {
public constructor(
public readonly projectInfo: ProjectInfo,
public readonly program: ts.Program,
public readonly stdlib: string) { }
public readonly stdlib: string,
options: AssemblerOptions) {

this._reservedWordsWarningsDisabled = !!options.reservedWordsWarningsDisabled;
}

private get _typeChecker(): ts.TypeChecker {
return this.program.getTypeChecker();
Expand Down Expand Up @@ -1026,6 +1039,9 @@ export class Assembler implements Emitter {
}

private _warnAboutReservedWords(symbol: ts.Symbol) {
if (this._reservedWordsWarningsDisabled) {
return;
}
const reservingLanguages = isReservedName(symbol.name);
if (reservingLanguages) {
this._diagnostic(ts.getNameOfDeclaration(symbol.valueDeclaration) || symbol.valueDeclaration,
Expand Down
9 changes: 8 additions & 1 deletion packages/jsii/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface CompilerOptions {
projectReferences?: boolean;
/** Whether to fail when a warning is emitted */
failOnWarnings?: boolean;
/**
* Do not emit warnings for reserved words.
* @default false (warnings are emitted)
*/
readonly reservedWordsWarningsDisabled?: boolean;
}

export interface TypescriptConfig {
Expand Down Expand Up @@ -159,7 +164,9 @@ export class Compiler implements Emitter {
// jsii warnings will appear. However, the Assembler might throw an exception
// because broken/missing type information might lead it to fail completely.
try {
const assembler = new Assembler(this.options.projectInfo, program, stdlib);
const assembler = new Assembler(this.options.projectInfo, program, stdlib, {
reservedWordsWarningsDisabled: this.options.reservedWordsWarningsDisabled
});
const assmEmit = await assembler.emit();
if (assmEmit.emitSkipped) {
LOG.error('Type model errors prevented the JSII assembly from being created');
Expand Down