From 7be80ce7909f5ec814cb669da8e18068aec9525d Mon Sep 17 00:00:00 2001 From: hronro Date: Fri, 27 Jul 2018 14:04:17 +0800 Subject: [PATCH] use `import` syntax to import Inferno namespace --- src/updateSourceFile.ts | 18 ++++++++---------- tests/references/Component1.jsx | 2 +- tests/references/Component2.jsx | 2 +- tests/references/Component3.jsx | 2 +- tests/references/Component4.jsx | 2 +- tests/references/advancedExpression.jsx | 2 +- tests/references/advancedWithImports.jsx | 2 +- tests/references/childrenProps1.jsx | 2 +- tests/references/childrenProps10.jsx | 2 +- tests/references/childrenProps11.jsx | 2 +- tests/references/childrenProps2.jsx | 2 +- tests/references/childrenProps3.jsx | 2 +- tests/references/childrenProps4.jsx | 2 +- tests/references/childrenProps5.jsx | 2 +- tests/references/childrenProps6.jsx | 2 +- tests/references/childrenProps7.jsx | 2 +- tests/references/childrenProps8.jsx | 2 +- tests/references/childrenProps9.jsx | 2 +- tests/references/div.jsx | 2 +- tests/references/divSelfClosed.jsx | 2 +- .../divWithAttributeReturningJSX.jsx | 2 +- tests/references/divWithChild.jsx | 2 +- .../divWithChildAndClassExpression.jsx | 2 +- tests/references/divWithChildAndClassName.jsx | 2 +- tests/references/divWithChildExpression.jsx | 2 +- .../divWithChildExpressionAdvanced.jsx | 2 +- tests/references/divWithClassAsVariable.jsx | 2 +- tests/references/divWithEvents.jsx | 2 +- .../references/divWithNoAssignedAttributes.jsx | 2 +- .../functionalComponentLifeCycle.jsx | 2 +- tests/references/htmlFor.jsx | 2 +- tests/references/specialFlags1.jsx | 2 +- tests/references/specialFlags2.jsx | 2 +- tests/references/specialFlags3.jsx | 2 +- tests/references/specialFlags4.jsx | 2 +- tests/references/specialFlags5.jsx | 2 +- tests/references/spreadAttribute1.jsx | 2 +- tests/references/spreadAttribute2.jsx | 2 +- tests/references/svgAttributeFillOpacity.jsx | 2 +- tests/references/svgAttributeStrokeWidth.jsx | 2 +- tests/references/svgAttributeXlinkHref.jsx | 2 +- tests/references/unknownClass.jsx | 2 +- tests/references/whitespaceAfterClosingTag.jsx | 2 +- 43 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/updateSourceFile.ts b/src/updateSourceFile.ts index af740c5..1c1ff4c 100644 --- a/src/updateSourceFile.ts +++ b/src/updateSourceFile.ts @@ -30,17 +30,15 @@ export default (sourceFile: ts.SourceFile, context) => { } statements.unshift( - ts.createVariableStatement(undefined, [ - ts.createVariableDeclaration( - "Inferno", + ts.createImportDeclaration( + undefined, + undefined, + ts.createImportClause( undefined, - ts.createCall( - ts.createIdentifier("require"), - [], - [ts.createLiteral("inferno")] - ) - ) - ]) + ts.createNamespaceImport(ts.createIdentifier("Inferno")) + ), + ts.createLiteral("inferno") + ) ); return ts.updateSourceFileNode(sourceFile, statements); diff --git a/tests/references/Component1.jsx b/tests/references/Component1.jsx index 0dd5662..5c57053 100644 --- a/tests/references/Component1.jsx +++ b/tests/references/Component1.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com, { "children": a }); diff --git a/tests/references/Component2.jsx b/tests/references/Component2.jsx index b1558b5..48c67b1 100644 --- a/tests/references/Component2.jsx +++ b/tests/references/Component2.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com, { "children": [a, b, diff --git a/tests/references/Component3.jsx b/tests/references/Component3.jsx index 07b5a3f..af2c72e 100644 --- a/tests/references/Component3.jsx +++ b/tests/references/Component3.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createComponentVNode = Inferno.createComponentVNode; var createVNode = Inferno.createVNode; diff --git a/tests/references/Component4.jsx b/tests/references/Component4.jsx index 213dcfd..ca307e7 100644 --- a/tests/references/Component4.jsx +++ b/tests/references/Component4.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Context.Provider); diff --git a/tests/references/advancedExpression.jsx b/tests/references/advancedExpression.jsx index 7d7af03..2ca2915 100644 --- a/tests/references/advancedExpression.jsx +++ b/tests/references/advancedExpression.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; var createVNode = Inferno.createVNode; function MyComponent(props) { diff --git a/tests/references/advancedWithImports.jsx b/tests/references/advancedWithImports.jsx index 6c6c917..1846cd6 100644 --- a/tests/references/advancedWithImports.jsx +++ b/tests/references/advancedWithImports.jsx @@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || (function () { if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { - define(["require", "exports", "inferno", "inferno-component", "./components/Incrementer"], factory); + define(["require", "exports", "inferno", "inferno", "inferno-component", "./components/Incrementer"], factory); } })(function (require, exports) { "use strict"; diff --git a/tests/references/childrenProps1.jsx b/tests/references/childrenProps1.jsx index 8c64e4f..b1b3e7d 100644 --- a/tests/references/childrenProps1.jsx +++ b/tests/references/childrenProps1.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", null, createTextVNode("test"), 2); diff --git a/tests/references/childrenProps10.jsx b/tests/references/childrenProps10.jsx index 28e80f6..df702bd 100644 --- a/tests/references/childrenProps10.jsx +++ b/tests/references/childrenProps10.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "foo"); diff --git a/tests/references/childrenProps11.jsx b/tests/references/childrenProps11.jsx index 995a11d..b910b0b 100644 --- a/tests/references/childrenProps11.jsx +++ b/tests/references/childrenProps11.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Context.Provider, { "children": "test" }); diff --git a/tests/references/childrenProps2.jsx b/tests/references/childrenProps2.jsx index 5c3fe95..484c918 100644 --- a/tests/references/childrenProps2.jsx +++ b/tests/references/childrenProps2.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", null, createTextVNode("ab"), 2); diff --git a/tests/references/childrenProps3.jsx b/tests/references/childrenProps3.jsx index 5c3fe95..484c918 100644 --- a/tests/references/childrenProps3.jsx +++ b/tests/references/childrenProps3.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", null, createTextVNode("ab"), 2); diff --git a/tests/references/childrenProps4.jsx b/tests/references/childrenProps4.jsx index 6559c6c..4608edf 100644 --- a/tests/references/childrenProps4.jsx +++ b/tests/references/childrenProps4.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com, { "children": "test" }); diff --git a/tests/references/childrenProps5.jsx b/tests/references/childrenProps5.jsx index acd3e94..2eafb6b 100644 --- a/tests/references/childrenProps5.jsx +++ b/tests/references/childrenProps5.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com, { "children": "ab" }); diff --git a/tests/references/childrenProps6.jsx b/tests/references/childrenProps6.jsx index acd3e94..2eafb6b 100644 --- a/tests/references/childrenProps6.jsx +++ b/tests/references/childrenProps6.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com, { "children": "ab" }); diff --git a/tests/references/childrenProps7.jsx b/tests/references/childrenProps7.jsx index 5b9f594..1805043 100644 --- a/tests/references/childrenProps7.jsx +++ b/tests/references/childrenProps7.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, Com); diff --git a/tests/references/childrenProps8.jsx b/tests/references/childrenProps8.jsx index 8220a24..8b70664 100644 --- a/tests/references/childrenProps8.jsx +++ b/tests/references/childrenProps8.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createComponentVNode = Inferno.createComponentVNode; var createVNode = Inferno.createVNode; diff --git a/tests/references/childrenProps9.jsx b/tests/references/childrenProps9.jsx index 58835ba..ea33bdc 100644 --- a/tests/references/childrenProps9.jsx +++ b/tests/references/childrenProps9.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "foo", null, createVNode(1, "span", null, createTextVNode("b"), 2), 2); diff --git a/tests/references/div.jsx b/tests/references/div.jsx index 40dbb87..653e9a9 100644 --- a/tests/references/div.jsx +++ b/tests/references/div.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div"); diff --git a/tests/references/divSelfClosed.jsx b/tests/references/divSelfClosed.jsx index 40dbb87..653e9a9 100644 --- a/tests/references/divSelfClosed.jsx +++ b/tests/references/divSelfClosed.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div"); diff --git a/tests/references/divWithAttributeReturningJSX.jsx b/tests/references/divWithAttributeReturningJSX.jsx index 7c01763..3581c32 100644 --- a/tests/references/divWithAttributeReturningJSX.jsx +++ b/tests/references/divWithAttributeReturningJSX.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, null, 1, { "foo": function () { return (createVNode(1, "div", null, null, 1, { "bar": true })); } }); diff --git a/tests/references/divWithChild.jsx b/tests/references/divWithChild.jsx index 499e572..ede4f8d 100644 --- a/tests/references/divWithChild.jsx +++ b/tests/references/divWithChild.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", null, createTextVNode("1"), 2); diff --git a/tests/references/divWithChildAndClassExpression.jsx b/tests/references/divWithChildAndClassExpression.jsx index 27c091c..3dbc301 100644 --- a/tests/references/divWithChildAndClassExpression.jsx +++ b/tests/references/divWithChildAndClassExpression.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", "first" + "second", createTextVNode("1"), 2); diff --git a/tests/references/divWithChildAndClassName.jsx b/tests/references/divWithChildAndClassName.jsx index a736e05..c6dac1b 100644 --- a/tests/references/divWithChildAndClassName.jsx +++ b/tests/references/divWithChildAndClassName.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", "first second", createTextVNode("1"), 2); diff --git a/tests/references/divWithChildExpression.jsx b/tests/references/divWithChildExpression.jsx index 2799d7c..63299f3 100644 --- a/tests/references/divWithChildExpression.jsx +++ b/tests/references/divWithChildExpression.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, test, 0); diff --git a/tests/references/divWithChildExpressionAdvanced.jsx b/tests/references/divWithChildExpressionAdvanced.jsx index c34b206..c147128 100644 --- a/tests/references/divWithChildExpressionAdvanced.jsx +++ b/tests/references/divWithChildExpressionAdvanced.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, false && [ createVNode(1, "div"), diff --git a/tests/references/divWithClassAsVariable.jsx b/tests/references/divWithClassAsVariable.jsx index b477453..3065c2f 100644 --- a/tests/references/divWithClassAsVariable.jsx +++ b/tests/references/divWithClassAsVariable.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", variable, createTextVNode("1"), 2); diff --git a/tests/references/divWithEvents.jsx b/tests/references/divWithEvents.jsx index 612f51f..f6283d2 100644 --- a/tests/references/divWithEvents.jsx +++ b/tests/references/divWithEvents.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", variable, createTextVNode("1"), 2, { "id": "test", "onClick": func }); diff --git a/tests/references/divWithNoAssignedAttributes.jsx b/tests/references/divWithNoAssignedAttributes.jsx index 4c92143..5972b18 100644 --- a/tests/references/divWithNoAssignedAttributes.jsx +++ b/tests/references/divWithNoAssignedAttributes.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, null, 1, { "foo": true, "Bar": true, "STAR": true }); diff --git a/tests/references/functionalComponentLifeCycle.jsx b/tests/references/functionalComponentLifeCycle.jsx index da97bb6..3e78267 100644 --- a/tests/references/functionalComponentLifeCycle.jsx +++ b/tests/references/functionalComponentLifeCycle.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, FunctionalComponent, null, null, { "onComponentDidMount": mounted }); diff --git a/tests/references/htmlFor.jsx b/tests/references/htmlFor.jsx index dfa2bd4..9c022ca 100644 --- a/tests/references/htmlFor.jsx +++ b/tests/references/htmlFor.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "label", null, createVNode(64, "input", null, null, 1, { "id": id, "name": name, "value": value, "onChange": onChange, "onInput": onInput, "onKeyup": onKeyup, "onFocus": onFocus, "onClick": onClick, "type": "number", "pattern": "[0-9]+([,\\.][0-9]+)?", "inputMode": "numeric", "min": minimum }), 2, { "for": id }); diff --git a/tests/references/specialFlags1.jsx b/tests/references/specialFlags1.jsx index fd1456e..31b7e60 100644 --- a/tests/references/specialFlags1.jsx +++ b/tests/references/specialFlags1.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, magic, 8); diff --git a/tests/references/specialFlags2.jsx b/tests/references/specialFlags2.jsx index 87c0852..57d91ab 100644 --- a/tests/references/specialFlags2.jsx +++ b/tests/references/specialFlags2.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, magic, 2); diff --git a/tests/references/specialFlags3.jsx b/tests/references/specialFlags3.jsx index f51488b..96d9413 100644 --- a/tests/references/specialFlags3.jsx +++ b/tests/references/specialFlags3.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "div", null, createTextVNode("text"), 2); diff --git a/tests/references/specialFlags4.jsx b/tests/references/specialFlags4.jsx index 643ef18..0c38297 100644 --- a/tests/references/specialFlags4.jsx +++ b/tests/references/specialFlags4.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(1, "div", null, test, 4); diff --git a/tests/references/specialFlags5.jsx b/tests/references/specialFlags5.jsx index 39f688e..0427442 100644 --- a/tests/references/specialFlags5.jsx +++ b/tests/references/specialFlags5.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(2049, "div"); diff --git a/tests/references/spreadAttribute1.jsx b/tests/references/spreadAttribute1.jsx index 66c2fc1..7f44a1f 100644 --- a/tests/references/spreadAttribute1.jsx +++ b/tests/references/spreadAttribute1.jsx @@ -6,7 +6,7 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { } return t; }; -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var normalizeProps = Inferno.normalizeProps; var createVNode = Inferno.createVNode; normalizeProps(createVNode(1, "div", null, null, 1, __assign({}, props, { "foo": "bar" }))); diff --git a/tests/references/spreadAttribute2.jsx b/tests/references/spreadAttribute2.jsx index 58b99a4..f290552 100644 --- a/tests/references/spreadAttribute2.jsx +++ b/tests/references/spreadAttribute2.jsx @@ -6,7 +6,7 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { } return t; }; -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var normalizeProps = Inferno.normalizeProps; var createVNode = Inferno.createVNode; normalizeProps(createVNode(1, "div", null, null, 1, __assign({}, this.props, { "foo": "bar" }))); diff --git a/tests/references/svgAttributeFillOpacity.jsx b/tests/references/svgAttributeFillOpacity.jsx index 726f1b9..1014bbb 100644 --- a/tests/references/svgAttributeFillOpacity.jsx +++ b/tests/references/svgAttributeFillOpacity.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(32, "svg", null, createVNode(1, "rect", null, null, 1, { "fill-opacity": "1" }), 2); diff --git a/tests/references/svgAttributeStrokeWidth.jsx b/tests/references/svgAttributeStrokeWidth.jsx index 25a04ca..33feae9 100644 --- a/tests/references/svgAttributeStrokeWidth.jsx +++ b/tests/references/svgAttributeStrokeWidth.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(32, "svg", null, createVNode(1, "rect", null, null, 1, { "stroke-width": "1px" }), 2); diff --git a/tests/references/svgAttributeXlinkHref.jsx b/tests/references/svgAttributeXlinkHref.jsx index c5cb9ce..2066922 100644 --- a/tests/references/svgAttributeXlinkHref.jsx +++ b/tests/references/svgAttributeXlinkHref.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createVNode = Inferno.createVNode; createVNode(32, "svg", null, createVNode(1, "use", null, null, 1, { "xlink:href": "#tester" }), 2); diff --git a/tests/references/unknownClass.jsx b/tests/references/unknownClass.jsx index ff083f4..d494362 100644 --- a/tests/references/unknownClass.jsx +++ b/tests/references/unknownClass.jsx @@ -1,3 +1,3 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createComponentVNode = Inferno.createComponentVNode; createComponentVNode(2, UnkownClass, { "className": "first second", "children": "1" }); diff --git a/tests/references/whitespaceAfterClosingTag.jsx b/tests/references/whitespaceAfterClosingTag.jsx index 0f87a4e..85710ae 100644 --- a/tests/references/whitespaceAfterClosingTag.jsx +++ b/tests/references/whitespaceAfterClosingTag.jsx @@ -1,4 +1,4 @@ -var Inferno = require("inferno"); +import * as Inferno from "inferno"; var createTextVNode = Inferno.createTextVNode; var createVNode = Inferno.createVNode; createVNode(1, "p", null, [createVNode(1, "span", null, createTextVNode("hello"), 2), createTextVNode(" world")], 4);