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

chore: update jsii to 0.7.4 #687

Merged
merged 3 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 30 additions & 3 deletions packages/@aws-cdk/cdk/lib/core/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Construct } from './construct';

export type ConstructConstructor = { new (...args: any[]): Construct };

export namespace jsx {

/**
Expand All @@ -19,13 +21,13 @@ export namespace jsx {
* @param children Array of children
* @returns element tree
*/
export function create(type: any, props: any, ...children: any[]) {
export function create(type: ConstructConstructor, props: any, ...children: JSX.Element[]): JSX.Element {
if (!(type.prototype instanceof Construct)) {
throw new Error('All nodes must derive from Construct: ' + type);
}

return {
type, props, children
type, props: props || {}, children
};
}

Expand All @@ -36,7 +38,7 @@ export namespace jsx {
* @param parent Optional parent for the construct tree
* @returns A Construct object
*/
export function construct(tree: any, parent?: Construct): Construct {
export function construct(tree: JSX.Element, parent?: Construct): Construct {
const id = (tree.props && tree.props.id) || '';
const root = new tree.type(parent, id, tree.props); // create root
createChildren(root, tree.children);
Expand All @@ -50,5 +52,30 @@ export namespace jsx {
createChildren(childObj, child.children);
}
}
}

declare global {
namespace JSX {
/**
* Declare JSX.Element to be the lazy specification of a Construct
*/
export interface Element {
type: ConstructConstructor;

props: any;

children: JSX.Element[];
}

interface ElementAttributesProperty {
// Property of the object that TSC will use to see the allowable
// parameters for every type.
jsxProps: any;
}

interface IntrinsicAttributes {
// Properties used by the framework, not by the individual classes.
id: string;
}
}
}
6 changes: 4 additions & 2 deletions packages/@aws-cdk/cdk/test/core/test.jsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export = {
};

class MyRoot extends Root {
protected jsx: any;
protected jsxProps: any;
}

interface MyConstructProps {
Expand All @@ -46,11 +46,13 @@ interface MyConstructProps {
}

class MyConstruct extends Construct {
public foo: number;

/**
* This syntax tells TypeScript which properties are required for this construct.
* Only classes with the "jsx" property can be used in JSX syntax.
*/
protected jsx?: MyConstructProps;
protected jsxProps?: MyConstructProps;

private str: string;

Expand Down
20 changes: 10 additions & 10 deletions packages/@aws-cdk/cfnspec/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/simple-resource-bundler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading