Skip to content

Commit

Permalink
linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Mar 28, 2022
1 parent c10e0e2 commit 1bec42e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
33 changes: 22 additions & 11 deletions packages/jsii/lib/transforms/deprecation-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export class DeprecationWarningsInjector {
if (spec.isDeprecated(type) && spec.isEnumType(type)) {
// The type is deprecated
tryStatements.push(
createWarningFunctionCall(
type.fqn,
type.docs?.deprecated,
),
createWarningFunctionCall(type.fqn, type.docs?.deprecated),
);
isEmpty = false;
}
Expand Down Expand Up @@ -579,10 +576,7 @@ class Transformer {
classType: spec.ClassType,
method: spec.Method | spec.Initializer,
) {
const statements = createWarningStatementForElement(
method,
classType,
);
const statements = createWarningStatementForElement(method, classType);
for (const parameter of Object.values(method.parameters ?? {})) {
const parameterType =
this.assembly.types && spec.isNamedTypeReference(parameter.type)
Expand Down Expand Up @@ -806,11 +800,28 @@ function wrapWithRethrow(
ts.createCatchClause(
ts.createVariableDeclaration('error'),
ts.createBlock([
// If this is a DeprecationError, trim its stack trace to surface level before re-throwing,
// so we don't carry out possibly confusing frames from injected code. That can be toggled
// off by setting JSII_DEBUG=1, so we can also diagnose in-injected code faults.
ts.createIf(
ts.createBinary(
ts.createPropertyAccess(ts.createIdentifier('error'), 'name'),
ts.SyntaxKind.EqualsEqualsEqualsToken,
ts.createLiteral(DEPRECATION_ERROR),
ts.createBinary(
ts.createPropertyAccess(
ts.createPropertyAccess(
ts.createIdentifier('process'),
'env',
),
'JSII_DEBUG',
),
ts.SyntaxKind.ExclamationEqualsEqualsToken,
ts.createLiteral('1'),
),
ts.SyntaxKind.AmpersandAmpersandToken,
ts.createBinary(
ts.createPropertyAccess(ts.createIdentifier('error'), 'name'),
ts.SyntaxKind.EqualsEqualsEqualsToken,
ts.createLiteral(DEPRECATION_ERROR),
),
),
ts.createBlock([
ts.createExpressionStatement(
Expand Down
12 changes: 6 additions & 6 deletions packages/jsii/test/deprecation-warnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.print(\\"testpkg.Foo#bar\\", \\"Use something else\\");
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, this.bar);
}
throw error;
Expand Down Expand Up @@ -510,7 +510,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.testpkg_A(a);
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, this.bar);
}
throw error;
Expand Down Expand Up @@ -552,7 +552,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.print(\\"testpkg.Foo#x\\", \\"Use something else\\");
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, Object.getOwnPropertyDescriptor(this, \\"x\\").get);
}
throw error;
Expand Down Expand Up @@ -595,7 +595,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.print(\\"testpkg.Foo#x\\", \\"Use something else\\");
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, Object.getOwnPropertyDescriptor(this, \\"x\\").get);
}
throw error;
Expand All @@ -605,7 +605,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.print(\\"testpkg.Foo#x\\", \\"Use something else\\");
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, Object.getOwnPropertyDescriptor(this, \\"x\\").set);
}
throw error;
Expand Down Expand Up @@ -643,7 +643,7 @@ describe('Call injections', () => {
jsiiDeprecationWarnings.print(\\"testpkg.Foo\\", \\"Use something else\\");
}
catch (error) {
if (error.name === \\"DeprecationError\\") {
if (process.env.JSII_DEBUG !== \\"1\\" && error.name === \\"DeprecationError\\") {
Error.captureStackTrace(error, this.constructor);
}
throw error;
Expand Down

0 comments on commit 1bec42e

Please sign in to comment.