Initial Import
This commit is contained in:
Родитель
a16d992713
Коммит
33d76f5b95
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
dist
|
||||
test/definitions/**/*.cs
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Mocha Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/dist/TsToCSharpTests.js",
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}/src/TStoCSharp.ts",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/**/*.js"
|
||||
],
|
||||
"args": [
|
||||
"./test/definitions/interfaces/Comments.d.ts"
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,741 @@
|
|||
{
|
||||
"name": "tstocsharp",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/chai": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.2.tgz",
|
||||
"integrity": "sha512-D8uQwKYUw2KESkorZ27ykzXgvkDJYXVEihGklgfp5I4HUP8D6IxtcdLTMB1emjQiWzV7WZ5ihm1cxIzVwjoleQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "2.2.48",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz",
|
||||
"integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "9.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.0.tgz",
|
||||
"integrity": "sha512-zkYho6/4wZyX6o9UQ8rd0ReEaiEYNNCqYFIAACe2Tf9DrYlgzWW27OigYHnnztnnZQwVRpwWmZKegFmDpinIsA==",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
|
||||
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
|
||||
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
|
||||
"dev": true
|
||||
},
|
||||
"argparse": {
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz",
|
||||
"integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"sprintf-js": "1.0.3"
|
||||
}
|
||||
},
|
||||
"array-differ": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/array-differ/-/array-differ-1.0.0.tgz",
|
||||
"integrity": "sha1-7/UuN1gknTO+QCuLuOVkuytdQDE="
|
||||
},
|
||||
"array-union": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz",
|
||||
"integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=",
|
||||
"requires": {
|
||||
"array-uniq": "1.0.3"
|
||||
}
|
||||
},
|
||||
"array-uniq": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz",
|
||||
"integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY="
|
||||
},
|
||||
"arrify": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
|
||||
"integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0="
|
||||
},
|
||||
"assertion-error": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
|
||||
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
|
||||
"dev": true
|
||||
},
|
||||
"babel-code-frame": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
|
||||
"integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "1.1.3",
|
||||
"esutils": "2.0.2",
|
||||
"js-tokens": "3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-styles": "2.2.1",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"has-ansi": "2.0.0",
|
||||
"strip-ansi": "3.0.1",
|
||||
"supports-color": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
||||
"requires": {
|
||||
"balanced-match": "1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
},
|
||||
"browser-stdout": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
|
||||
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
|
||||
"dev": true
|
||||
},
|
||||
"builtin-modules": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
|
||||
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
|
||||
"dev": true
|
||||
},
|
||||
"camel-case": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz",
|
||||
"integrity": "sha1-yjw2iKTpzzpM2nd9xNy8cTJJz3M=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2",
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"chai": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
|
||||
"integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assertion-error": "1.1.0",
|
||||
"check-error": "1.0.2",
|
||||
"deep-eql": "3.0.1",
|
||||
"get-func-name": "2.0.0",
|
||||
"pathval": "1.1.0",
|
||||
"type-detect": "4.0.8"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz",
|
||||
"integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-styles": "3.2.0",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"supports-color": "4.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-styles": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz",
|
||||
"integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-convert": "1.9.1"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
|
||||
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"change-case": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/change-case/-/change-case-3.0.1.tgz",
|
||||
"integrity": "sha1-7l9a0EFa0a2egHLPSc1M+nZgpVQ=",
|
||||
"requires": {
|
||||
"camel-case": "3.0.0",
|
||||
"constant-case": "2.0.0",
|
||||
"dot-case": "2.1.1",
|
||||
"header-case": "1.0.1",
|
||||
"is-lower-case": "1.1.3",
|
||||
"is-upper-case": "1.1.2",
|
||||
"lower-case": "1.1.4",
|
||||
"lower-case-first": "1.0.2",
|
||||
"no-case": "2.3.2",
|
||||
"param-case": "2.1.1",
|
||||
"pascal-case": "2.0.1",
|
||||
"path-case": "2.1.1",
|
||||
"sentence-case": "2.1.1",
|
||||
"snake-case": "2.1.0",
|
||||
"swap-case": "1.1.2",
|
||||
"title-case": "2.1.1",
|
||||
"upper-case": "1.1.3",
|
||||
"upper-case-first": "1.1.2"
|
||||
}
|
||||
},
|
||||
"check-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
|
||||
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
|
||||
"dev": true
|
||||
},
|
||||
"code-block-writer": {
|
||||
"version": "6.2.0",
|
||||
"resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-6.2.0.tgz",
|
||||
"integrity": "sha1-9DbTuaI5vcW9lvXHt2TeW3zekzk="
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz",
|
||||
"integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-name": "1.1.3"
|
||||
}
|
||||
},
|
||||
"color-name": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||
"dev": true
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
|
||||
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"constant-case": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/constant-case/-/constant-case-2.0.0.tgz",
|
||||
"integrity": "sha1-QXV2TTidP6nI7NKRhu1gBSQ7akY=",
|
||||
"requires": {
|
||||
"snake-case": "2.1.0",
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"deep-eql": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
|
||||
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"type-detect": "4.0.8"
|
||||
}
|
||||
},
|
||||
"diff": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz",
|
||||
"integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==",
|
||||
"dev": true
|
||||
},
|
||||
"dot-case": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/dot-case/-/dot-case-2.1.1.tgz",
|
||||
"integrity": "sha1-NNzzf1Co6TwrO8qLt/uRVcfaO+4=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2"
|
||||
}
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||
"dev": true
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz",
|
||||
"integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==",
|
||||
"dev": true
|
||||
},
|
||||
"esutils": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
|
||||
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
|
||||
"dev": true
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"get-func-name": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
|
||||
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
|
||||
"dev": true
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
"inflight": "1.0.6",
|
||||
"inherits": "2.0.3",
|
||||
"minimatch": "3.0.4",
|
||||
"once": "1.4.0",
|
||||
"path-is-absolute": "1.0.1"
|
||||
}
|
||||
},
|
||||
"globby": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz",
|
||||
"integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=",
|
||||
"requires": {
|
||||
"array-union": "1.0.2",
|
||||
"glob": "7.1.2",
|
||||
"object-assign": "4.1.1",
|
||||
"pify": "2.3.0",
|
||||
"pinkie-promise": "2.0.1"
|
||||
}
|
||||
},
|
||||
"growl": {
|
||||
"version": "1.10.3",
|
||||
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz",
|
||||
"integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==",
|
||||
"dev": true
|
||||
},
|
||||
"has-ansi": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
|
||||
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-regex": "2.1.1"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
|
||||
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=",
|
||||
"dev": true
|
||||
},
|
||||
"he": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
|
||||
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
|
||||
"dev": true
|
||||
},
|
||||
"header-case": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/header-case/-/header-case-1.0.1.tgz",
|
||||
"integrity": "sha1-lTWXMZfBRLCWE81l0xfvGZY70C0=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2",
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"requires": {
|
||||
"once": "1.4.0",
|
||||
"wrappy": "1.0.2"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"is-lower-case": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/is-lower-case/-/is-lower-case-1.1.3.tgz",
|
||||
"integrity": "sha1-fhR75HaNxGbbO/shzGCzHmrWk5M=",
|
||||
"requires": {
|
||||
"lower-case": "1.1.4"
|
||||
}
|
||||
},
|
||||
"is-upper-case": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/is-upper-case/-/is-upper-case-1.1.2.tgz",
|
||||
"integrity": "sha1-jQsfp+eTOh5YSDYA7H2WYcuvdW8=",
|
||||
"requires": {
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"js-tokens": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
|
||||
"integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=",
|
||||
"dev": true
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
|
||||
"integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"argparse": "1.0.9",
|
||||
"esprima": "4.0.0"
|
||||
}
|
||||
},
|
||||
"lower-case": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz",
|
||||
"integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw="
|
||||
},
|
||||
"lower-case-first": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/lower-case-first/-/lower-case-first-1.0.2.tgz",
|
||||
"integrity": "sha1-5dp8JvKacHO+AtUrrJmA5ZIq36E=",
|
||||
"requires": {
|
||||
"lower-case": "1.1.4"
|
||||
}
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"requires": {
|
||||
"brace-expansion": "1.1.8"
|
||||
}
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"mocha": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.0.tgz",
|
||||
"integrity": "sha512-ukB2dF+u4aeJjc6IGtPNnJXfeby5d4ZqySlIBT0OEyva/DrMjVm5HkQxKnHDLKEfEQBsEnwTg9HHhtPHJdTd8w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"browser-stdout": "1.3.0",
|
||||
"commander": "2.11.0",
|
||||
"debug": "3.1.0",
|
||||
"diff": "3.3.1",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"glob": "7.1.2",
|
||||
"growl": "1.10.3",
|
||||
"he": "1.1.1",
|
||||
"mkdirp": "0.5.1",
|
||||
"supports-color": "4.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
|
||||
"integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
|
||||
"dev": true
|
||||
},
|
||||
"multimatch": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/multimatch/-/multimatch-2.1.0.tgz",
|
||||
"integrity": "sha1-nHkGoi+0wCkZ4vX3UWG0zb1LKis=",
|
||||
"requires": {
|
||||
"array-differ": "1.0.0",
|
||||
"array-union": "1.0.2",
|
||||
"arrify": "1.0.1",
|
||||
"minimatch": "3.0.4"
|
||||
}
|
||||
},
|
||||
"no-case": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz",
|
||||
"integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==",
|
||||
"requires": {
|
||||
"lower-case": "1.1.4"
|
||||
}
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"requires": {
|
||||
"wrappy": "1.0.2"
|
||||
}
|
||||
},
|
||||
"param-case": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/param-case/-/param-case-2.1.1.tgz",
|
||||
"integrity": "sha1-35T9jPZTHs915r75oIWPvHK+Ikc=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2"
|
||||
}
|
||||
},
|
||||
"pascal-case": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-2.0.1.tgz",
|
||||
"integrity": "sha1-LVeNNFX2YNpl7KGO+VtODekSdh4=",
|
||||
"requires": {
|
||||
"camel-case": "3.0.0",
|
||||
"upper-case-first": "1.1.2"
|
||||
}
|
||||
},
|
||||
"path-case": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/path-case/-/path-case-2.1.1.tgz",
|
||||
"integrity": "sha1-lLgDfDctP+KQbkZbtF4l0ibo7qU=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2"
|
||||
}
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||
},
|
||||
"path-parse": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
|
||||
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
|
||||
"dev": true
|
||||
},
|
||||
"pathval": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
|
||||
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
|
||||
"dev": true
|
||||
},
|
||||
"pify": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
|
||||
},
|
||||
"pinkie": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
||||
"integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA="
|
||||
},
|
||||
"pinkie-promise": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
|
||||
"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
|
||||
"requires": {
|
||||
"pinkie": "2.0.4"
|
||||
}
|
||||
},
|
||||
"resolve": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz",
|
||||
"integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"path-parse": "1.0.5"
|
||||
}
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==",
|
||||
"dev": true
|
||||
},
|
||||
"sentence-case": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/sentence-case/-/sentence-case-2.1.1.tgz",
|
||||
"integrity": "sha1-H24t2jnBaL+S0T+G1KkYkz9mftQ=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2",
|
||||
"upper-case-first": "1.1.2"
|
||||
}
|
||||
},
|
||||
"snake-case": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/snake-case/-/snake-case-2.1.0.tgz",
|
||||
"integrity": "sha1-Qb2xtz8w7GagTU4srRt2OH1NbZ8=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2"
|
||||
}
|
||||
},
|
||||
"sprintf-js": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
|
||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
|
||||
"dev": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-regex": "2.1.1"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
|
||||
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
|
||||
"dev": true
|
||||
},
|
||||
"swap-case": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/swap-case/-/swap-case-1.1.2.tgz",
|
||||
"integrity": "sha1-w5IDpFhzhfrTyFCgvRvK+ggZdOM=",
|
||||
"requires": {
|
||||
"lower-case": "1.1.4",
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"title-case": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/title-case/-/title-case-2.1.1.tgz",
|
||||
"integrity": "sha1-PhJyFtpY0rxb7PE3q5Ha46fNj6o=",
|
||||
"requires": {
|
||||
"no-case": "2.3.2",
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"ts-simple-ast": {
|
||||
"version": "6.12.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-simple-ast/-/ts-simple-ast-6.12.0.tgz",
|
||||
"integrity": "sha1-vSMtf8fj8f8SEYJVTeHkIW+SWC4=",
|
||||
"requires": {
|
||||
"code-block-writer": "6.2.0",
|
||||
"globby": "6.1.0",
|
||||
"multimatch": "2.1.0",
|
||||
"object-assign": "4.1.1",
|
||||
"typescript": "2.7.1"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz",
|
||||
"integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==",
|
||||
"dev": true
|
||||
},
|
||||
"tslint": {
|
||||
"version": "5.9.1",
|
||||
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.9.1.tgz",
|
||||
"integrity": "sha1-ElX4ej/1frCw4fDmEKi0dIBGya4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"babel-code-frame": "6.26.0",
|
||||
"builtin-modules": "1.1.1",
|
||||
"chalk": "2.3.0",
|
||||
"commander": "2.14.1",
|
||||
"diff": "3.3.1",
|
||||
"glob": "7.1.2",
|
||||
"js-yaml": "3.10.0",
|
||||
"minimatch": "3.0.4",
|
||||
"resolve": "1.5.0",
|
||||
"semver": "5.5.0",
|
||||
"tslib": "1.9.0",
|
||||
"tsutils": "2.21.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"tsutils": {
|
||||
"version": "2.21.0",
|
||||
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.21.0.tgz",
|
||||
"integrity": "sha512-zlOHTYtTwvTiKxUyAU8wiKzPpAgwZrGjb7AY18VUlxuCgBiTMVorIl5HjrCT8V64Hm34RI1BZITJMVQpBLMxVg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"type-detect": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
|
||||
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.1.tgz",
|
||||
"integrity": "sha512-bqB1yS6o9TNA9ZC/MJxM0FZzPnZdtHj0xWK/IZ5khzVqdpGul/R/EIiHRgFXlwTD7PSIaYVnGKq1QgMCu2mnqw=="
|
||||
},
|
||||
"upper-case": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz",
|
||||
"integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg="
|
||||
},
|
||||
"upper-case-first": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/upper-case-first/-/upper-case-first-1.1.2.tgz",
|
||||
"integrity": "sha1-XXm+3P8UQZUY/S7bCgUHybaFkRU=",
|
||||
"requires": {
|
||||
"upper-case": "1.1.3"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "tstocsharp",
|
||||
"version": "1.0.0",
|
||||
"description": "Emit C# code from TypeScrypt definition files",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"change-case": "^3.0.1",
|
||||
"ts-simple-ast": "^6.12.0",
|
||||
"typescript": "^2.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.2",
|
||||
"@types/mocha": "^2.2.48",
|
||||
"@types/node": "^9.4.0",
|
||||
"chai": "^4.1.2",
|
||||
"mocha": "^5.0.0",
|
||||
"tslint": "^5.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node ./dist/TStoCSharp.js",
|
||||
"test": "npm run lint && mocha ./dist/TsToCSharpTests.js",
|
||||
"build-ts": "tsc",
|
||||
"watch-ts": "tsc -w",
|
||||
"lint": "tslint test/**/*.d.ts -t verbose"
|
||||
},
|
||||
"author": "Kenneth J. Pouncey",
|
||||
"license": "MIT"
|
||||
}
|
|
@ -0,0 +1,334 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import * as sast from "ts-simple-ast";
|
||||
import { TypeGuards } from 'ts-simple-ast';
|
||||
import {Context} from "./Context";
|
||||
|
||||
import {
|
||||
addWhitespace,
|
||||
emitStatic,
|
||||
addLeadingComment,
|
||||
addTrailingComment,
|
||||
addSemicolon,
|
||||
addComma,
|
||||
endNode,
|
||||
} from './GeneratorHelpers';
|
||||
|
||||
const ReferenceTypeMap = [
|
||||
ts.SyntaxKind.StringKeyword
|
||||
]
|
||||
|
||||
const ValueTypeMap = [
|
||||
ts.SyntaxKind.NumberKeyword,
|
||||
ts.SyntaxKind.BooleanKeyword
|
||||
]
|
||||
|
||||
const ValueTypeTextMap = [
|
||||
"double",
|
||||
"bool"
|
||||
]
|
||||
|
||||
export function emit(node: sast.Node, context: Context): string {
|
||||
if ((emitter as any)[node.getKind()]) {
|
||||
return (emitter as any)[node.getKind()](node, context);
|
||||
}
|
||||
throw new Error(`Unknown node kind ${ts.SyntaxKind[node.getKind()]}`);
|
||||
}
|
||||
|
||||
export function emitTypeNode(node: sast.Node, context: Context) : string {
|
||||
|
||||
// tslint:disable-next-line cyclomatic-complexity
|
||||
switch (node.getKind()) {
|
||||
case ts.SyntaxKind.TypeReference:
|
||||
return emitTypeReference(<sast.TypeReferenceNode>node, context);
|
||||
case ts.SyntaxKind.VoidKeyword:
|
||||
return emitVoidType(node, context);
|
||||
case ts.SyntaxKind.NumberKeyword:
|
||||
return emitNumberType(node, context);
|
||||
case ts.SyntaxKind.BooleanKeyword:
|
||||
return emitBooleanType(node, context);
|
||||
case ts.SyntaxKind.UnionType:
|
||||
return emitUnionType(<sast.UnionTypeNode>node, context);
|
||||
case ts.SyntaxKind.StringKeyword:
|
||||
return emitStringType(node, context);
|
||||
case ts.SyntaxKind.AnyKeyword:
|
||||
return emitAnyType(node, context);
|
||||
case ts.SyntaxKind.ArrayType:
|
||||
return emitArrayType(node, context);
|
||||
default:
|
||||
throw new Error(`Unknown TypeNode kind ${ts.SyntaxKind[node.getKind()]}`);
|
||||
}
|
||||
}
|
||||
|
||||
function emitExpressionWithTypeArguments(node: sast.ExpressionWithTypeArguments,
|
||||
context: Context): string {
|
||||
const source: string[] = [];
|
||||
addWhitespace(source, node, context);
|
||||
source.push(emit(node.getExpression(), context));
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitPropertyName(node: (sast.PropertyName
|
||||
| sast.StringLiteral
|
||||
| sast.ComputedPropertyName
|
||||
| sast.NumericLiteral), context: Context): string {
|
||||
switch (node.getKind()) {
|
||||
case ts.SyntaxKind.Identifier:
|
||||
return emitIdentifier(node, context);
|
||||
case ts.SyntaxKind.StringLiteral:
|
||||
return emitStringLiteral(<sast.StringLiteral>node, context);
|
||||
case ts.SyntaxKind.ComputedPropertyName:
|
||||
return emitComputedPropertyName(<sast.ComputedPropertyName>node, context);
|
||||
case ts.SyntaxKind.FirstLiteralToken:
|
||||
return emitFirstLiteralToken(<sast.NumericLiteral>node, context);
|
||||
default:
|
||||
throw new Error(`Unknown PropertyName kind '${ts.SyntaxKind[node.getKind()]}'`);
|
||||
}
|
||||
}
|
||||
|
||||
export function emitComputedPropertyName(node: sast.ComputedPropertyName,
|
||||
context: Context): string {
|
||||
const source: string[] = [];
|
||||
emitStatic(source, '[', node, context);
|
||||
addWhitespace(source, node, context);
|
||||
//source.push(emitExpression(node.expression, context));
|
||||
emitStatic(source, ']', node, context);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitModifierable(node: sast.Node, context: Context): string {
|
||||
if ((emitter as any)[node.getKind()]) {
|
||||
return (emitter as any)[node.getKind()](node, context);
|
||||
}
|
||||
throw new Error(`Unknown Modifierable node kind ${ts.SyntaxKind[node.getKind()]}`);
|
||||
}
|
||||
|
||||
export function emitPublicKeyword(node: sast.Node, context: Context): string {
|
||||
return _emitKeyword('public', node, context);
|
||||
}
|
||||
|
||||
export function emitInterfaceKeyword(node: sast.Node, context: Context): string {
|
||||
return _emitKeyword('interface', node, context);
|
||||
}
|
||||
|
||||
// We will not emit the readonly keyword but we do need to update the context
|
||||
export function emitReadonlyKeyword(node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addWhitespace(source, node, context);
|
||||
context.offset = node.getEnd();
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function _emitKeyword(keyword: string, node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addWhitespace(source, node, context);
|
||||
source.push(keyword);
|
||||
context.offset += node.getWidth();
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function _emitType(type: string, node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
source.push(type);
|
||||
context.offset = node.getEnd();
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitIdentifier(node: (sast.Identifier
|
||||
| sast.PropertyName
|
||||
| sast.EntityName),
|
||||
context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
|
||||
const literal = (node.getText().trim().length > 0)
|
||||
? node.getText().trim()
|
||||
: node.getFullText().substring(node.getStart(), node.getEnd()).trim()
|
||||
|
||||
source.push(literal);
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitStringLiteral(node: sast.StringLiteral, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
const literal: string = (node as any).newText
|
||||
? (node as any).newText
|
||||
: node.getFullText().substring(node.getStart(), node.getEnd()).trim();
|
||||
source.push(literal);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitFirstLiteralToken(node: sast.NumericLiteral, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
const literal = (node as any).newText
|
||||
? (node as any).newText
|
||||
: node.getFullText().substring(node.getStart(), node.getEnd()).trim();
|
||||
source.push(literal);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitVoidType(node: sast.Node, context: Context): string {
|
||||
return _emitType('void', node, context);
|
||||
}
|
||||
|
||||
export function emitBooleanType(node: sast.Node, context: Context): string {
|
||||
return _emitType('bool', node, context);
|
||||
}
|
||||
|
||||
export function emitNumberType(node: sast.Node, context: Context): string {
|
||||
return _emitType('double', node, context);
|
||||
}
|
||||
|
||||
export function emitStringType(node: sast.Node, context: Context): string {
|
||||
return _emitType('string', node, context);
|
||||
}
|
||||
|
||||
export function emitAnyType(node: sast.Node, context: Context): string {
|
||||
return _emitType('Object', node, context);
|
||||
}
|
||||
|
||||
export function emitArrayType(node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
const at = <sast.ArrayTypeNode>node;
|
||||
const element = at.getElementTypeNode();
|
||||
emitTypeNode(element, context);
|
||||
source.push(emitTypeNode(element, context));
|
||||
source.push("[");
|
||||
source.push("]");
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitTypeReference(node: sast.TypeReferenceNode, context: Context): string {
|
||||
const source: string[] = [];
|
||||
source.push(node.getText());
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitNumberKeyword(node: sast.Node, context: Context): string {
|
||||
return _emitKeyword('double', node, context);
|
||||
}
|
||||
|
||||
function isUnionNullable(node: sast.UnionTypeNode): boolean {
|
||||
|
||||
for (let i = 0, n = node.getTypeNodes().length; i < n; i++) {
|
||||
if (TypeGuards.isNullLiteral(node.getTypeNodes()[i]) || TypeGuards.isUndefinedKeyword(node.getTypeNodes()[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// at this time UnionTypeNode is not wrapped by ts-simple-ast
|
||||
export function emitUnionType(node: sast.UnionTypeNode, context: Context): string {
|
||||
const source: string[] = [];
|
||||
|
||||
addTrailingComment(source, context.offset, node, context);
|
||||
addWhitespace(source, context.offset, node, context);
|
||||
const isNullable = isUnionNullable(node);
|
||||
|
||||
var typeMap = [];
|
||||
|
||||
for (let i = 0, n = node.getTypeNodes().length; i < n; i++) {
|
||||
if (node.getTypeNodes()[i].getKind() !== ts.SyntaxKind.NullKeyword &&
|
||||
node.getTypeNodes()[i].getKind() !== ts.SyntaxKind.UndefinedKeyword)
|
||||
{
|
||||
typeMap.push(node.getTypeNodes()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// If we only have one left the output the strongly typed union
|
||||
if (typeMap.length === 1)
|
||||
{
|
||||
var mappedType = typeMap[0];
|
||||
|
||||
// We need to treat arrays a little different to insert the "?" nullable.
|
||||
if (TypeGuards.isArrayTypeNode(mappedType))
|
||||
{
|
||||
const arrayDef = emitTypeNode(mappedType, context);
|
||||
const arrayDefBracket = arrayDef.indexOf("[");
|
||||
|
||||
// if the union type was nullable then insert the "?" for value types.
|
||||
if (isNullable && ValueTypeTextMap.indexOf(arrayDef.substring(0,arrayDefBracket)) !== -1)
|
||||
{
|
||||
source.push(arrayDef.substr(0, arrayDefBracket) + "?" + arrayDef.substr(arrayDefBracket));
|
||||
}
|
||||
else
|
||||
{
|
||||
source.push(arrayDef);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
source.push(emitTypeNode(mappedType, context));
|
||||
if (isNullable && ValueTypeMap.indexOf(mappedType.getKind()) !== -1)
|
||||
{
|
||||
source.push("?");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// or output a generic object
|
||||
source.push("object");
|
||||
}
|
||||
|
||||
context.offset = node.getEnd();
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitTypeParameter(source: string[], node: sast.TypeParameterDeclaration, context: Context): void {
|
||||
// if (node.typeParameters) {
|
||||
// emitStatic(source, '<', node, context);
|
||||
// for (let i = 0, n = node.typeParameters.length; i < n; i++) {
|
||||
// addTrailingComment(source, context.offset, node, context);
|
||||
// addWhitespace(source, node, context);
|
||||
// source.push(emit(node.typeParameters[i], context));
|
||||
// if ((i < n - 1) || node.typeParameters.hasTrailingComma) {
|
||||
// emitStatic(source, ',', node, context);
|
||||
// }
|
||||
// }
|
||||
// emitStatic(source, '>', node, context);
|
||||
// }
|
||||
}
|
||||
|
||||
function _emitToken(source: string[], token: string, node: sast.Node, context: Context): void {
|
||||
addLeadingComment(source, node, context);
|
||||
emitStatic(source, token, node, context);
|
||||
}
|
||||
|
||||
export function emitCloseBraceToken(node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
_emitToken(source, '}', node, context);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
export function emitFirstPunctuation(node: sast.Node, context: Context): string {
|
||||
const source: string[] = [];
|
||||
_emitToken(source, node.getText(), node, context);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
const emitter = {
|
||||
[ts.SyntaxKind.CloseBraceToken]: emitCloseBraceToken,
|
||||
[ts.SyntaxKind.FirstPunctuation]: emitFirstPunctuation,
|
||||
[ts.SyntaxKind.Identifier]: emitIdentifier,
|
||||
[ts.SyntaxKind.PublicKeyword]: emitPublicKeyword,
|
||||
[ts.SyntaxKind.ReadonlyKeyword]: emitReadonlyKeyword,
|
||||
[ts.SyntaxKind.ExpressionWithTypeArguments]: emitExpressionWithTypeArguments,
|
||||
[ts.SyntaxKind.InterfaceKeyword]: emitInterfaceKeyword,
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
export interface Context {
|
||||
offset: number;
|
||||
indent: number;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export class Stack<T> {
|
||||
_store: T[] = [];
|
||||
push(val: T) {
|
||||
this._store.push(val);
|
||||
}
|
||||
pop(): T | undefined {
|
||||
return this._store.pop();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
import * as ts from 'typescript';
|
||||
import * as sast from "ts-simple-ast";
|
||||
import {Context} from "./Context";
|
||||
|
||||
export function emitStatic(source: string[], text: string, node: sast.Node, context: Context): void {
|
||||
addWhitespace(source, node, context);
|
||||
source.push(text);
|
||||
context.offset += text.length;
|
||||
}
|
||||
|
||||
const whitespaces = /^([ \f\n\r\t\v\u0085\u00A0\u2028\u2029\u3000]+)/;
|
||||
export function addWhitespace(source: string[], node: sast.Node, context: Context): void;
|
||||
export function addWhitespace(source: string[], pos: number, node: sast.Node, context: Context): void;
|
||||
// tslint:disable-next-line:cyclomatic-complexity
|
||||
export function addWhitespace(source: string[], posOrNode: number|sast.Node, nodeOrContext: sast.Node|Context,
|
||||
optionalContext?: Context): void {
|
||||
const context = optionalContext || (nodeOrContext as Context);
|
||||
const node = optionalContext ? nodeOrContext as sast.Node : posOrNode as sast.Node;
|
||||
const pos = optionalContext ? posOrNode as number : node.getFullStart();
|
||||
|
||||
if (context.offset > node.getEnd()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.offset <= node.getFullStart()) {
|
||||
const text = node.getSourceFile().getFullText().substring(pos, node.getEnd());
|
||||
const leadingWhitespace = text.match(whitespaces);
|
||||
if (leadingWhitespace) {
|
||||
context.offset = pos + leadingWhitespace[1].length;
|
||||
source.push(leadingWhitespace[1]);
|
||||
}
|
||||
} else {
|
||||
const text = node.getSourceFile().getFullText().substring(context.offset, node.getEnd());
|
||||
const trailingWhitespace = text.match(whitespaces);
|
||||
if (trailingWhitespace) {
|
||||
context.offset = context.offset + trailingWhitespace[1].length;
|
||||
source.push(trailingWhitespace[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function addLeadingComment(source: string[], node: sast.Node, context: Context): void;
|
||||
export function addLeadingComment(source: string[], pos: number, node: sast.Node, context: Context): void;
|
||||
export function addLeadingComment(source: string[], posOrNode: number|sast.Node, nodeOrContext: sast.Node|Context,
|
||||
optionalContext?: Context): void {
|
||||
const context = optionalContext || (nodeOrContext as Context);
|
||||
const node = optionalContext ? nodeOrContext as sast.Node : posOrNode as sast.Node;
|
||||
const pos = optionalContext ? posOrNode as number : node.getFullStart();
|
||||
|
||||
const text = node.getSourceFile().getFullText();
|
||||
const ranges = ts.getLeadingCommentRanges(text, pos);
|
||||
if (ranges) {
|
||||
source.push(ranges
|
||||
.map(range => {
|
||||
if (context.offset <= range.pos) {
|
||||
const prefix = text.substring(context.offset, range.pos);
|
||||
const comment = prefix + text.substring(range.pos, range.end);
|
||||
context.offset += comment.length;
|
||||
return comment;
|
||||
}
|
||||
return '';
|
||||
})
|
||||
.join(''));
|
||||
}
|
||||
}
|
||||
|
||||
export function addTrailingComment(source: string[], node: sast.Node, context: Context): void;
|
||||
export function addTrailingComment(source: string[], pos: number, node: sast.Node, context: Context): void;
|
||||
export function addTrailingComment(source: string[], posOrNode: number|sast.Node, nodeOrContext: sast.Node|Context,
|
||||
optionalContext?: Context): void {
|
||||
var context = optionalContext || (nodeOrContext as Context);
|
||||
const node = optionalContext ? nodeOrContext as sast.Node : posOrNode as sast.Node;
|
||||
const pos = optionalContext ? posOrNode as number : node.getEnd();
|
||||
|
||||
const text = node.getSourceFile().getFullText();
|
||||
const ranges = ts.getTrailingCommentRanges(text, pos);
|
||||
if (ranges) {
|
||||
source.push(ranges
|
||||
.map(range => {
|
||||
if (context.offset <= range.pos) {
|
||||
const prefix = text.substring(context.offset, range.pos);
|
||||
const comment = prefix + text.substring(range.pos, range.end);
|
||||
context.offset += comment.length;
|
||||
return comment;
|
||||
}
|
||||
return '';
|
||||
})
|
||||
.join(''));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function addSemicolon(source: string[], node: sast.Node, context: Context): void {
|
||||
|
||||
if (node.getSourceFile().getFullText().substring(context.offset).trim().startsWith(';')) {
|
||||
emitStatic(source, ';', node, context);
|
||||
}
|
||||
}
|
||||
|
||||
export function addComma(source: string[], node: sast.Node, context: Context): void {
|
||||
if (node.getSourceFile().getFullText().substring(context.offset).trim().startsWith(',')) {
|
||||
emitStatic(source, ',', node, context);
|
||||
}
|
||||
}
|
||||
|
||||
export function endNode(node: sast.Node, context: Context): void {
|
||||
const end = node.getEnd();
|
||||
if (context.offset < end) {
|
||||
context.offset = end;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import * as ts from 'typescript';
|
||||
import * as fs from "fs";
|
||||
import Ast from "ts-simple-ast";
|
||||
import * as path from "path";
|
||||
|
||||
import { TsToCSharpGenerator } from './TsToCSharpGenerator';
|
||||
|
||||
class Startup {
|
||||
|
||||
public static main(): number {
|
||||
|
||||
const fileNames = process.argv.slice(2);
|
||||
console.log('Starting Generation for file(s): ' + fileNames.join(","));
|
||||
fileNames.forEach(fileName => {
|
||||
const ast = new Ast({
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ESNext
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Resolving File: ' + fileName + ' => ' + path.resolve(fileName));
|
||||
var sf = ast.addSourceFileIfExists(path.resolve(fileName));
|
||||
var sfs = ast.getSourceFiles();
|
||||
sfs.forEach(
|
||||
astSourceFile => {
|
||||
let sourceCode = TsToCSharpGenerator(astSourceFile, {
|
||||
offset: 0,
|
||||
indent: 0
|
||||
}
|
||||
);
|
||||
// output the file.
|
||||
var filePath = path.dirname(fileName);
|
||||
var justTheName = path.basename(fileName,".d.ts");
|
||||
|
||||
fs.writeFileSync(path.join(filePath,justTheName+".cs"), sourceCode);
|
||||
}
|
||||
)
|
||||
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Startup.main();
|
|
@ -0,0 +1,424 @@
|
|||
import * as ts from 'typescript';
|
||||
import * as sast from "ts-simple-ast";
|
||||
import { TypeGuards } from 'ts-simple-ast';
|
||||
|
||||
import * as emitter from "./CSharpEmitter";
|
||||
import {Stack} from "./DataStructures";
|
||||
import {Context} from "./Context";
|
||||
|
||||
import {
|
||||
addWhitespace,
|
||||
emitStatic,
|
||||
addLeadingComment,
|
||||
addTrailingComment,
|
||||
addSemicolon,
|
||||
addComma,
|
||||
endNode,
|
||||
} from './GeneratorHelpers';
|
||||
|
||||
const ContextStack = new Stack<number>();
|
||||
|
||||
export function TsToCSharpGenerator(node: sast.SourceFile, context: Context): string {
|
||||
const source: string[] = [];
|
||||
visitStatements(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
endNode(node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function visit(node: sast.Node, context: Context): string {
|
||||
if ((visitor as any)[node.getKind()]) {
|
||||
return (visitor as any)[node.getKind()](node, context);
|
||||
}
|
||||
throw new Error(`Unknown node kind ${ts.SyntaxKind[node.getKind()]}`);
|
||||
}
|
||||
|
||||
// tslint:disable-next-line cyclomatic-complexity
|
||||
function visitStatements(source: string[], node: sast.SourceFile, context: Context): void {
|
||||
node.getStatements().forEach(statement =>
|
||||
source.push(visitStatement(statement, context))
|
||||
);
|
||||
}
|
||||
|
||||
// tslint:disable-next-line cyclomatic-complexity
|
||||
function visitStatement(node: sast.Statement, context: Context): string {
|
||||
|
||||
switch (node.getKind()) {
|
||||
case ts.SyntaxKind.VariableStatement:
|
||||
return visitVariableStatement(node as sast.VariableStatement, context);
|
||||
case ts.SyntaxKind.InterfaceDeclaration:
|
||||
return visitInterfaceDeclaration(node as sast.InterfaceDeclaration, context);
|
||||
default:
|
||||
throw new Error(`Unknown statement kind '${ts.SyntaxKind[node.getKind()]}'`);
|
||||
}
|
||||
}
|
||||
|
||||
function visitModifiers(source: string[], node: sast.ModifierableNode, context: Context): void {
|
||||
node.getModifiers().forEach(modifier => {
|
||||
source.push(emitter.emitModifierable(modifier, context));
|
||||
});
|
||||
}
|
||||
|
||||
function visitTypeParameters(source: string[], node: sast.TypeParameteredNode, context: Context): void {
|
||||
node.getTypeParameters().forEach(typeParameter => {
|
||||
emitter.emitTypeParameter(source, typeParameter, context);
|
||||
});
|
||||
}
|
||||
|
||||
function visitMembers(source: string[],
|
||||
node: (sast.InterfaceDeclaration | sast.ClassDeclaration),
|
||||
context: Context): void {
|
||||
|
||||
let members = node.getAllMembers();
|
||||
for (var x = 0; x < members.length; x++)
|
||||
{
|
||||
let member = members[x];
|
||||
source.push(visit(member, context));
|
||||
addTrailingComment(source, context.offset, node, context);
|
||||
}
|
||||
}
|
||||
|
||||
function isIndexerReadOnly(node: ts.IndexSignatureDeclaration): boolean {
|
||||
|
||||
if (node.modifiers) {
|
||||
var modifers = node.modifiers;
|
||||
for (let i = 0, n = node.modifiers.length; i < n; i++) {
|
||||
if (node.modifiers[i].kind === ts.SyntaxKind.ReadonlyKeyword)
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function visitIndexSignature(node: sast.IndexSignatureDeclaration, context: Context): string {
|
||||
const source: string[] = [];
|
||||
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
|
||||
// visit the modifiers.
|
||||
visitModifiers(source, node, context);
|
||||
|
||||
if (node.compilerNode.modifiers) {
|
||||
node.compilerNode.modifiers.forEach(modifier => {
|
||||
source.push(emitter.emitModifierable(sast.createWrappedNode(modifier), context));
|
||||
});
|
||||
}
|
||||
|
||||
// let's push the name node offset so spacing will be ok.
|
||||
// Modifiers seem to mess the spacing up with whitespace
|
||||
context.offset = node.getKeyNameNode().getStart();
|
||||
pushContext(context);
|
||||
|
||||
// // emit our property type which is at the end.
|
||||
source.push(visitTypeNode(node.getReturnTypeNode(), context));
|
||||
|
||||
// make sure we put a spacer in there but we do not have optional properties.
|
||||
// if (node.hasQuestionToken()) {
|
||||
// source.push("? ");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
source.push(" ");
|
||||
//}
|
||||
|
||||
// now reposition back to the start
|
||||
swapContext(context);
|
||||
|
||||
emitStatic(source, 'this[', node, context);
|
||||
|
||||
source.push(visitTypeNode(node.getKeyTypeNode(), context));
|
||||
source.push(" ");
|
||||
source.push(emitter.emitPropertyName(node.getKeyNameNode(), context));
|
||||
|
||||
emitStatic(source, ']', node, context);
|
||||
|
||||
if (node.isReadonly())
|
||||
{
|
||||
source.push(" { get; }");
|
||||
}
|
||||
else
|
||||
{
|
||||
source.push(" { get; set; }");
|
||||
}
|
||||
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function visitHeritageClause(node: sast.HeritageClause, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
let clauseTypes = node.getTypes();
|
||||
let n = clauseTypes.length;
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
for (var t = 0; t < n; t++)
|
||||
{
|
||||
source.push(emitter.emit(clauseTypes[t], context));
|
||||
if ((t < n - 1)) {
|
||||
source.push(", ");
|
||||
}
|
||||
};
|
||||
}
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function visitHeritageClauses(source: string[],
|
||||
node: (sast.HeritageClauseableNode),
|
||||
context: Context): void {
|
||||
|
||||
let ancestors = node.getHeritageClauses();
|
||||
let n = ancestors.length;
|
||||
if (ancestors.length > 0)
|
||||
{
|
||||
source.push(" : ");
|
||||
for (var x = 0; x < n; x++)
|
||||
{
|
||||
let leaf = ancestors[x];
|
||||
source.push(visit(leaf, context));
|
||||
if ((x < n - 1)) {
|
||||
source.push(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function visitInterfaceDeclaration(node: sast.InterfaceDeclaration, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
|
||||
visitModifiers(source, node, context);
|
||||
|
||||
// emit first punctuation which should be an opening brace.
|
||||
source.push(emitter.emit(node.getFirstChildByKind(ts.SyntaxKind.InterfaceKeyword), context));
|
||||
|
||||
addWhitespace(source, node, context);
|
||||
source.push(emitter.emitIdentifier(node.getNameNode(), context));
|
||||
|
||||
visitHeritageClauses(source, node, context);
|
||||
|
||||
addTrailingComment(source, context.offset, node, context);
|
||||
|
||||
// emit first punctuation which should be an opening brace.
|
||||
source.push(emitter.emit(node.getFirstChildByKind(ts.SyntaxKind.FirstPunctuation), context));
|
||||
|
||||
addTrailingComment(source, context.offset, node, context);
|
||||
|
||||
visitMembers(source, node, context);
|
||||
addLeadingComment(source, context.offset, node, context);
|
||||
|
||||
// emit the closing brace
|
||||
source.push(emitter.emit(node.getLastToken(), context));
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function visitTypeNode(node: sast.Node,
|
||||
context: Context): string {
|
||||
return emitter.emitTypeNode(node, context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function visitPropertySignature(node: sast.PropertySignature, context: Context): string {
|
||||
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
|
||||
visitModifiers(source, node, context);
|
||||
|
||||
// let's push the name node offset so spacing will be ok.
|
||||
// Modifiers seem to mess the spacing up with whitespace
|
||||
context.offset = node.getNameNode().getStart();
|
||||
pushContext(context);
|
||||
|
||||
// emit our property type which is at the end.
|
||||
source.push(visitTypeNode(node.getTypeNode(), context));
|
||||
|
||||
// make sure we put a spacer in there but we do not have optional properties.
|
||||
// if (node.hasQuestionToken()) {
|
||||
// source.push("? ");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
source.push(" ");
|
||||
//}
|
||||
|
||||
// now reposition back to the start
|
||||
swapContext(context);
|
||||
|
||||
source.push(emitter.emitPropertyName(node.getNameNode(), context));
|
||||
|
||||
if (node.isReadonly())
|
||||
{
|
||||
source.push(" { get; }");
|
||||
}
|
||||
else
|
||||
{
|
||||
source.push(" { get; set; }");
|
||||
}
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
function cloneObject(obj: any) {
|
||||
var clone:any = {};
|
||||
for(var i in obj) {
|
||||
if(obj[i] != null && typeof(obj[i])=="object")
|
||||
clone[i] = cloneObject(obj[i]);
|
||||
else
|
||||
clone[i] = obj[i];
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
function pushContext(context: Context): void
|
||||
{
|
||||
// save off our original context
|
||||
ContextStack.push(context.offset);
|
||||
}
|
||||
|
||||
function swapContext(context: Context)
|
||||
{
|
||||
|
||||
// save off our original context
|
||||
var swap:number = ContextStack.pop();
|
||||
pushContext(context);
|
||||
context.offset = swap;
|
||||
}
|
||||
|
||||
function popContext(context: Context)
|
||||
{
|
||||
context.offset = ContextStack.pop();
|
||||
}
|
||||
|
||||
function visitParameter(source: string[], node: sast.ParameterDeclaration, context: Context): void {
|
||||
|
||||
// We have to take into account that the type follows the name
|
||||
// let's push the parameter name node offset so spacing will be ok.
|
||||
// The comma separator will mess the spacing up with whitespace
|
||||
context.offset = node.getStart();
|
||||
pushContext(context);
|
||||
|
||||
// emit our parameter type which is at the end.
|
||||
source.push(visitTypeNode(node.getTypeNode(), context));
|
||||
// let's also put a spacer in there
|
||||
source.push(" ");
|
||||
|
||||
// now reposition back to the start
|
||||
swapContext(context);
|
||||
|
||||
source.push(emitter.emitPropertyName(node.getNameNode(), context));
|
||||
|
||||
// now reposition back to the start
|
||||
popContext(context);
|
||||
|
||||
}
|
||||
|
||||
function visitParameters(source: string[], node: sast.ParameteredNode, context: Context): void {
|
||||
|
||||
var parmList = node.getParameters();
|
||||
|
||||
let n = node.getParameters().length;
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
for (let p = 0; p < n; p++)
|
||||
{
|
||||
visitParameter(source, parmList[p], context);
|
||||
if (p < n - 1)
|
||||
{
|
||||
source.push(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// tslint:disable-next-line cyclomatic-complexity
|
||||
function visitMethodSignature(node: sast.MethodSignature, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
addWhitespace(source, node, context);
|
||||
|
||||
// let's push the name node offset so spacing will be ok.
|
||||
// Modifiers seem to mess the spacing up with whitespace
|
||||
context.offset = node.getNameNode().getStart();
|
||||
pushContext(context);
|
||||
|
||||
|
||||
// emit our method type which is at the end.
|
||||
source.push(visitTypeNode(node.getReturnTypeNode(), context));
|
||||
// make sure we put a spacer in there
|
||||
source.push(" ");
|
||||
|
||||
// now reposition back to the start
|
||||
swapContext(context);
|
||||
|
||||
visitTypeParameters(source, node, context);
|
||||
|
||||
source.push(emitter.emitPropertyName(node.getNameNode(), context));
|
||||
|
||||
emitStatic(source, '(', node, context);
|
||||
|
||||
visitParameters(source, node, context);
|
||||
|
||||
emitStatic(source, ')', node, context);
|
||||
|
||||
// Now reposition to the end of the method type
|
||||
popContext(context);
|
||||
|
||||
addSemicolon(source, node, context);
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, context.offset, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
|
||||
function visitVariableStatement(node: sast.VariableStatement, context: Context): string {
|
||||
const source: string[] = [];
|
||||
addLeadingComment(source, node, context);
|
||||
// emitModifiers(source, node, context);
|
||||
// source.push(emitVariableDeclarationList(node.declarationList, context));
|
||||
addSemicolon(source, node, context);
|
||||
endNode(node, context);
|
||||
addTrailingComment(source, node, context);
|
||||
return source.join('');
|
||||
}
|
||||
|
||||
|
||||
// function visitTypeParameter(node: sast.TypeParameterDeclaration, context: VisitorContext): string {
|
||||
// const source: string[] = [];
|
||||
// addWhitespace(source, node, context);
|
||||
// //source.push(emitter.emitIdentifier(node., context));
|
||||
// // if (node.constraint) {
|
||||
// // emitStatic(source, 'extends', node, context);
|
||||
// // addWhitespace(source, node, context);
|
||||
// // source.push(emitTypeNode(node.constraint, context));
|
||||
// // }
|
||||
// // if (node.default) {
|
||||
// // emitStatic(source, '=', node, context);
|
||||
// // addWhitespace(source, node, context);
|
||||
// // source.push(emitTypeNode(node.default, context));
|
||||
// // }
|
||||
// endNode(node, context);
|
||||
// return source.join('');
|
||||
// }
|
||||
|
||||
|
||||
const visitor = {
|
||||
[ts.SyntaxKind.SourceFile]: TsToCSharpGenerator,
|
||||
[ts.SyntaxKind.PropertySignature]: visitPropertySignature,
|
||||
[ts.SyntaxKind.MethodSignature]: visitMethodSignature,
|
||||
[ts.SyntaxKind.HeritageClause]: visitHeritageClause,
|
||||
[ts.SyntaxKind.IndexSignature]: visitIndexSignature,
|
||||
};
|
|
@ -0,0 +1,87 @@
|
|||
import * as path from "path";
|
||||
import * as ts from "typescript";
|
||||
import {expect} from "chai";
|
||||
import * as fs from "fs";
|
||||
import Ast from "ts-simple-ast";
|
||||
import {TsToCSharpGenerator} from "./TStoCSharpGenerator";
|
||||
|
||||
console.log("");
|
||||
console.log("TypeScript version: " + ts.version);
|
||||
console.log("Working Directory: " + __dirname);
|
||||
|
||||
const definitionsPath = "./test/definitions";
|
||||
const casesPath = "./test/cases";
|
||||
|
||||
const interfaceCases = [
|
||||
{should: "should generate simple interface", file: "Interface"},
|
||||
{should: "should generate simple interface with closing brackets on separate lines", file: "Interface2"},
|
||||
{should: "should generate simple interface with leading and trailing comments", file: "Comments"},
|
||||
{should: "should generate simple interface with leading and trailing comments on separate line", file: "Comments2"},
|
||||
{should: "should generate interface extending one interface", file: "Extends"},
|
||||
{should: "should generate interface with method that returns void", file: "MethodReturnVoid"},
|
||||
{should: "should generate interface with method that returns bool", file: "MethodReturnBool"},
|
||||
{should: "should generate interface with method that returns string", file: "MethodReturnString"},
|
||||
{should: "should generate interface with method that returns any", file: "MethodReturnAny"},
|
||||
{should: "should generate interface with method that returns type reference", file: "MethodReturnObject1"},
|
||||
{should: "should generate interface with 2 methods that returns type reference", file: "MethodReturnObject2"},
|
||||
{should: "should generate interface with method with string parm that returns bool", file: "MethodWithStringParmReturnBool"},
|
||||
{should: "should generate interface with method with string parms", file: "MethodWithStringParms"},
|
||||
{should: "should generate interface with method with string or null parms", file: "MethodWithStringOrNullParms"},
|
||||
{should: "should generate interface with method leading and trailing comments", file: "MethodComments"},
|
||||
{should: "should generate interface with string property", file: "StringProperty"},
|
||||
{should: "should generate interface with readonly object property", file: "ReadOnlyObjectProperty"},
|
||||
{should: "should generate interface with string or null property", file: "StringOrNullProperty"},
|
||||
{should: "should generate interface with number or null property", file: "NumberOrNullProperty"},
|
||||
{should: "should generate interface with boolean or null property", file: "BooleanOrNullProperty"},
|
||||
{should: "should generate interface with object or null property", file: "ObjOrNullProperty"},
|
||||
{should: "should generate interface with indexer", file: "IndexerProperty"},
|
||||
{should: "should generate interface with readonly indexer", file: "ReadOnlyIndexerProperty"},
|
||||
{should: "should generate interface with string indexer", file: "StringIndexerProperty"},
|
||||
{should: "should generate interface with string indexer", file: "StringIndexerProperty"},
|
||||
{should: "should generate interface with indexer property with leading and trailing comments", file: "IndexerPropertyComments"},
|
||||
{should: "should generate interface with number and object array", file: "ArrayProperty2"},
|
||||
{should: "should generate interface with nullable number array", file: "NumberArrayOrNullProperty"},
|
||||
{should: "should generate interface with nullable boolean array", file: "BooleanArrayOrNullProperty"},
|
||||
{should: "should generate interface with nullable object array", file: "ObjArrayOrNullProperty"},
|
||||
{should: "should generate interface with nullable string array", file: "StringArrayOrNullProperty"},
|
||||
|
||||
|
||||
|
||||
{should: "should generate interfaces extending one interface", file: "Extends2"},
|
||||
{should: "should generate multiple interfaces extending multiple interfaces", file: "Extends3"},
|
||||
|
||||
]
|
||||
|
||||
describe("TsToCSharpGenerator", () => {
|
||||
describe("interfaces", () => {
|
||||
|
||||
const testPath = "interfaces";
|
||||
|
||||
interfaceCases.forEach(testCase =>
|
||||
{
|
||||
|
||||
var testFile = testCase.file;
|
||||
|
||||
it(testCase.should, () => {
|
||||
const ast = new Ast({
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ESNext
|
||||
}
|
||||
});
|
||||
//console.log("Adding Source File: " + path.resolve(path.join(definitionsPath,testPath,testFile + ".d.ts")));
|
||||
ast.addSourceFileIfExists(path.resolve(path.join(definitionsPath,testPath,testFile + ".d.ts")));
|
||||
|
||||
var sourceFiles = ast.getSourceFiles();
|
||||
let sourceCode = TsToCSharpGenerator(sourceFiles[0], {
|
||||
offset: 0,
|
||||
indent: 0
|
||||
})
|
||||
//fs.writeFileSync(path.join(casesPath,testPath,testFile + ".cs"), sourceCode);
|
||||
var genCase = fs.readFileSync(path.join(casesPath,testPath,testFile + ".cs")).toString();
|
||||
expect(sourceCode).to.equal(genCase);
|
||||
});
|
||||
|
||||
}
|
||||
)
|
||||
});
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
interface MediaKeySystemConfiguration {
|
||||
string[] initDataTypes { get; set; }
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
interface Gamepad {
|
||||
double[] axes { get; }
|
||||
GamepadButton[] buttons { get; }
|
||||
bool connected { get; }
|
||||
string id { get; }
|
||||
double index { get; }
|
||||
string mapping { get; }
|
||||
double timestamp { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface GamepadFaux {
|
||||
bool?[] axesAvailable { get; }
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
interface RTCIceParameters {
|
||||
bool? iceLite { get; set; }
|
||||
string password { get; set; }
|
||||
string usernameFragment { get; set; }
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
// This is a leading comment
|
||||
interface EventTarget { // This is a trailing comment
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
// This is a leading comment
|
||||
interface EventTarget
|
||||
{ // This is a trailing comment
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
interface Node : EventTarget {}
|
|
@ -0,0 +1,7 @@
|
|||
interface EventTarget {
|
||||
bool dispatchEvent(Event evt);
|
||||
}
|
||||
|
||||
interface Node : EventTarget {
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
interface EventTarget {
|
||||
bool dispatchEvent(Event evt);
|
||||
}
|
||||
|
||||
interface Node : EventTarget {
|
||||
string nodeName { get; }
|
||||
double nodeType { get; }
|
||||
}
|
||||
|
||||
interface GlobalEventHandlers {
|
||||
}
|
||||
|
||||
interface ElementTraversal {
|
||||
double childElementCount { get; }
|
||||
}
|
||||
|
||||
interface NodeSelector {
|
||||
}
|
||||
|
||||
interface ChildNode {
|
||||
void remove();
|
||||
}
|
||||
|
||||
interface ParentNode {
|
||||
HTMLCollection children { get; }
|
||||
double childElementCount { get; }
|
||||
}
|
||||
|
||||
interface Element : Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode, ParentNode {
|
||||
DOMTokenList classList { get; }
|
||||
string className { get; set; }
|
||||
double clientHeight { get; }
|
||||
double clientLeft { get; }
|
||||
double clientTop { get; }
|
||||
double clientWidth { get; }
|
||||
string id { get; set; }
|
||||
string innerHTML { get; set; }
|
||||
double msContentZoomFactor { get; set; }
|
||||
string msRegionOverflow { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface FileList {
|
||||
File this[double index] { get; set; }
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
interface ClientRectList {
|
||||
// This is the length
|
||||
double length { get; } /* returns a number */
|
||||
ClientRect item(double index); // Return the ClientRect at the specified index
|
||||
/**
|
||||
* Retrieves a ClientRect object ClientRectList.
|
||||
*/
|
||||
ClientRect this[double index] { get; set; } // Return the ClientRect at the specified index
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
interface EventTarget {
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
interface EventTarget
|
||||
{}
|
|
@ -0,0 +1,10 @@
|
|||
interface HTMLFormElement : HTMLElement {
|
||||
/**
|
||||
* Returns whether a form will validate when it is submitted, without having to submit it.
|
||||
*/
|
||||
bool checkValidity(); // Returns bool
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
*/
|
||||
Object item(Object name, Object index); // Returns the any value
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface PaymentAddress {
|
||||
Object toJSON();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Node {
|
||||
bool hasAttributes();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
ClientRect getBoundingClientRect();
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
interface Element {
|
||||
ClientRect getBoundingClientRect();
|
||||
ClientRectList getClientRects();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface DOMError {
|
||||
string toString();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface EventTarget {
|
||||
void dispatchEvent();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
interface NamedNodeMap {
|
||||
double length { get; }
|
||||
Attr getNamedItem(string name);
|
||||
Attr getNamedItemNS(string namespaceURI, string localName);
|
||||
Attr item(double index);
|
||||
Attr removeNamedItem(string name);
|
||||
Attr removeNamedItemNS(string namespaceURI, string localName);
|
||||
Attr setNamedItem(Attr arg);
|
||||
Attr setNamedItemNS(Attr arg);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
bool hasAttribute(string name);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
void setAttribute(string name, string value);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Gamepad {
|
||||
double?[] axes { get; }
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
interface Coordinates {
|
||||
double accuracy { get; }
|
||||
double? altitude { get; }
|
||||
double? altitudeAccuracy { get; }
|
||||
double? heading { get; }
|
||||
double latitude { get; }
|
||||
double longitude { get; }
|
||||
double? speed { get; }
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
interface ServiceWorkerMessageEventInit : EventInit {
|
||||
Object data { get; set; }
|
||||
string lastEventId { get; set; }
|
||||
string origin { get; set; }
|
||||
MessagePort[] ports { get; set; }
|
||||
object source { get; set; }
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
interface DeviceAcceleration {
|
||||
double? x { get; }
|
||||
double? y { get; }
|
||||
double? z { get; }
|
||||
}
|
||||
|
||||
interface DeviceRotationRate {
|
||||
double? alpha { get; }
|
||||
double? beta { get; }
|
||||
double? gamma { get; }
|
||||
}
|
||||
|
||||
interface DeviceMotionEvent : Event {
|
||||
DeviceAcceleration acceleration { get; }
|
||||
DeviceAcceleration accelerationIncludingGravity { get; }
|
||||
double? interval { get; }
|
||||
DeviceRotationRate rotationRate { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface FileList {
|
||||
File this[double index] { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface HTMLElement {
|
||||
HTMLCollection children { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface WebGLRenderingContext {
|
||||
string[] getSupportedExtensions();
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
interface HTMLFormElement : HTMLElement {
|
||||
/**
|
||||
* Sets or retrieves a list of character encodings for input data that must be accepted by the server processing the form.
|
||||
*/
|
||||
string acceptCharset { get; set; }
|
||||
/**
|
||||
* Sets or retrieves the URL to which the form content is sent for processing.
|
||||
*/
|
||||
string action { get; set; }
|
||||
/**
|
||||
* Specifies whether autocomplete is applied to an editable text field.
|
||||
*/
|
||||
string autocomplete { get; set; }
|
||||
/**
|
||||
* Retrieves a collection, in source order, of all controls in a given form.
|
||||
*/
|
||||
HTMLFormControlsCollection elements { get; }
|
||||
/**
|
||||
* Sets or retrieves the MIME encoding for the form.
|
||||
*/
|
||||
string encoding { get; set; }
|
||||
/**
|
||||
* Sets or retrieves the encoding type for the form.
|
||||
*/
|
||||
string enctype { get; set; }
|
||||
/**
|
||||
* Sets or retrieves the number of objects in a collection.
|
||||
*/
|
||||
double length { get; }
|
||||
/**
|
||||
* Sets or retrieves how to send the form data to the server.
|
||||
*/
|
||||
string method { get; set; }
|
||||
/**
|
||||
* Sets or retrieves the name of the object.
|
||||
*/
|
||||
string name { get; set; }
|
||||
/**
|
||||
* Designates a form that is not validated when submitted.
|
||||
*/
|
||||
bool noValidate { get; set; }
|
||||
/**
|
||||
* Sets or retrieves the window or frame at which to target content.
|
||||
*/
|
||||
string target { get; set; }
|
||||
/**
|
||||
* Returns whether a form will validate when it is submitted, without having to submit it.
|
||||
*/
|
||||
bool checkValidity();
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
* @param name Variant of type Number or String that specifies the object or collection to retrieve. If this parameter is a Number, it is the zero-based index of the object. If this parameter is a string, all objects with matching name or id properties are retrieved, and a collection is returned if more than one match is made.
|
||||
* @param index Variant of type Number that specifies the zero-based index of the object to retrieve when a collection is returned.
|
||||
*/
|
||||
Object item(Object name, Object index);
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
*/
|
||||
Object namedItem(string name);
|
||||
/**
|
||||
* Fires when the user resets a form.
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Fires when a FORM is about to be submitted.
|
||||
*/
|
||||
void submit();
|
||||
bool reportValidity();
|
||||
Object this[string name] { get; set; }
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
interface Node : EventTarget {
|
||||
string baseURIa { get; }
|
||||
string baseURI { get; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface HTMLElement {
|
||||
string accessKey { get; set; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface MediaKeySystemConfiguration {
|
||||
initDataTypes?: string[];
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
interface Gamepad {
|
||||
readonly axes: number[];
|
||||
readonly buttons: GamepadButton[];
|
||||
readonly connected: boolean;
|
||||
readonly id: string;
|
||||
readonly index: number;
|
||||
readonly mapping: string;
|
||||
readonly timestamp: number;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface GamepadFaux {
|
||||
readonly axesAvailable: boolean[] | null;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
interface RTCIceParameters {
|
||||
iceLite?: boolean | null;
|
||||
password?: string;
|
||||
usernameFragment?: string;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
// This is a leading comment
|
||||
interface EventTarget { // This is a trailing comment
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
// This is a leading comment
|
||||
interface EventTarget
|
||||
{ // This is a trailing comment
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
interface Node extends EventTarget {}
|
|
@ -0,0 +1,7 @@
|
|||
interface EventTarget {
|
||||
dispatchEvent(evt: Event): boolean;
|
||||
}
|
||||
|
||||
interface Node extends EventTarget {
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
interface EventTarget {
|
||||
dispatchEvent(evt: Event): boolean;
|
||||
}
|
||||
|
||||
interface Node extends EventTarget {
|
||||
readonly nodeName: string;
|
||||
readonly nodeType: number;
|
||||
}
|
||||
|
||||
interface GlobalEventHandlers {
|
||||
}
|
||||
|
||||
interface ElementTraversal {
|
||||
readonly childElementCount: number;
|
||||
}
|
||||
|
||||
interface NodeSelector {
|
||||
}
|
||||
|
||||
interface ChildNode {
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
interface ParentNode {
|
||||
readonly children: HTMLCollection;
|
||||
readonly childElementCount: number;
|
||||
}
|
||||
|
||||
interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode, ParentNode {
|
||||
readonly classList: DOMTokenList;
|
||||
className: string;
|
||||
readonly clientHeight: number;
|
||||
readonly clientLeft: number;
|
||||
readonly clientTop: number;
|
||||
readonly clientWidth: number;
|
||||
id: string;
|
||||
innerHTML: string;
|
||||
msContentZoomFactor: number;
|
||||
readonly msRegionOverflow: string;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface FileList {
|
||||
[index: number]: File;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
interface ClientRectList {
|
||||
// This is the length
|
||||
readonly length: number; /* returns a number */
|
||||
item(index: number): ClientRect; // Return the ClientRect at the specified index
|
||||
/**
|
||||
* Retrieves a ClientRect object ClientRectList.
|
||||
*/
|
||||
[index: number]: ClientRect; // Return the ClientRect at the specified index
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
interface EventTarget {
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
interface EventTarget
|
||||
{}
|
|
@ -0,0 +1,10 @@
|
|||
interface HTMLFormElement extends HTMLElement {
|
||||
/**
|
||||
* Returns whether a form will validate when it is submitted, without having to submit it.
|
||||
*/
|
||||
checkValidity(): boolean; // Returns bool
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
*/
|
||||
item(name?: any, index?: any): any; // Returns the any value
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface PaymentAddress {
|
||||
toJSON(): any;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Node {
|
||||
hasAttributes(): boolean;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Performance {
|
||||
now(): number;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
getBoundingClientRect(): ClientRect;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
interface Element {
|
||||
getBoundingClientRect(): ClientRect;
|
||||
getClientRects(): ClientRectList;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface DOMError {
|
||||
toString(): string;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface EventTarget {
|
||||
dispatchEvent(): void;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
interface NamedNodeMap {
|
||||
readonly length: number;
|
||||
getNamedItem(name: string): Attr;
|
||||
getNamedItemNS(namespaceURI: string | null, localName: string | null): Attr;
|
||||
item(index: number): Attr;
|
||||
removeNamedItem(name: string): Attr;
|
||||
removeNamedItemNS(namespaceURI: string | null, localName: string | null): Attr;
|
||||
setNamedItem(arg: Attr): Attr;
|
||||
setNamedItemNS(arg: Attr): Attr;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
hasAttribute(name: string): boolean;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Element {
|
||||
setAttribute(name: string, value: string): void;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface Gamepad {
|
||||
readonly axes: number[] | null;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
interface Coordinates {
|
||||
readonly accuracy: number;
|
||||
readonly altitude: number | null;
|
||||
readonly altitudeAccuracy: number | null;
|
||||
readonly heading: number | null;
|
||||
readonly latitude: number;
|
||||
readonly longitude: number;
|
||||
readonly speed: number | null;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
interface ServiceWorkerMessageEventInit extends EventInit {
|
||||
data?: any;
|
||||
lastEventId?: string;
|
||||
origin?: string;
|
||||
ports?: MessagePort[] | null;
|
||||
source?: ServiceWorker | MessagePort | null;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
interface DeviceAcceleration {
|
||||
readonly x: number | null;
|
||||
readonly y: number | null;
|
||||
readonly z: number | null;
|
||||
}
|
||||
|
||||
interface DeviceRotationRate {
|
||||
readonly alpha: number | null;
|
||||
readonly beta: number | null;
|
||||
readonly gamma: number | null;
|
||||
}
|
||||
|
||||
interface DeviceMotionEvent extends Event {
|
||||
readonly acceleration: DeviceAcceleration | null;
|
||||
readonly accelerationIncludingGravity: DeviceAcceleration | null;
|
||||
readonly interval: number | null;
|
||||
readonly rotationRate: DeviceRotationRate | null;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface HTMLElement {
|
||||
readonly children: HTMLCollection;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface FileList {
|
||||
readonly [index: number]: File;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface WebGLRenderingContext {
|
||||
getSupportedExtensions(): string[] | null;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
interface HTMLFormElement extends HTMLElement {
|
||||
/**
|
||||
* Sets or retrieves a list of character encodings for input data that must be accepted by the server processing the form.
|
||||
*/
|
||||
acceptCharset: string;
|
||||
/**
|
||||
* Sets or retrieves the URL to which the form content is sent for processing.
|
||||
*/
|
||||
action: string;
|
||||
/**
|
||||
* Specifies whether autocomplete is applied to an editable text field.
|
||||
*/
|
||||
autocomplete: string;
|
||||
/**
|
||||
* Retrieves a collection, in source order, of all controls in a given form.
|
||||
*/
|
||||
readonly elements: HTMLFormControlsCollection;
|
||||
/**
|
||||
* Sets or retrieves the MIME encoding for the form.
|
||||
*/
|
||||
encoding: string;
|
||||
/**
|
||||
* Sets or retrieves the encoding type for the form.
|
||||
*/
|
||||
enctype: string;
|
||||
/**
|
||||
* Sets or retrieves the number of objects in a collection.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Sets or retrieves how to send the form data to the server.
|
||||
*/
|
||||
method: string;
|
||||
/**
|
||||
* Sets or retrieves the name of the object.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Designates a form that is not validated when submitted.
|
||||
*/
|
||||
noValidate: boolean;
|
||||
/**
|
||||
* Sets or retrieves the window or frame at which to target content.
|
||||
*/
|
||||
target: string;
|
||||
/**
|
||||
* Returns whether a form will validate when it is submitted, without having to submit it.
|
||||
*/
|
||||
checkValidity(): boolean;
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
* @param name Variant of type Number or String that specifies the object or collection to retrieve. If this parameter is a Number, it is the zero-based index of the object. If this parameter is a string, all objects with matching name or id properties are retrieved, and a collection is returned if more than one match is made.
|
||||
* @param index Variant of type Number that specifies the zero-based index of the object to retrieve when a collection is returned.
|
||||
*/
|
||||
item(name?: any, index?: any): any;
|
||||
/**
|
||||
* Retrieves a form object or an object from an elements collection.
|
||||
*/
|
||||
namedItem(name: string): any;
|
||||
/**
|
||||
* Fires when the user resets a form.
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Fires when a FORM is about to be submitted.
|
||||
*/
|
||||
submit(): void;
|
||||
reportValidity(): boolean;
|
||||
[name: string]: any;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
interface Node extends EventTarget {
|
||||
readonly baseURIa: string;
|
||||
readonly baseURI: string | null;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
interface HTMLElement {
|
||||
accessKey: string;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": [
|
||||
"node_modules/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
]
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended"
|
||||
],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"align": [
|
||||
true,
|
||||
"parameters",
|
||||
"statements"
|
||||
],
|
||||
"interface-name": [ false ],
|
||||
"max-line-length": [ false ],
|
||||
"member-access": false,
|
||||
"member-ordering": [
|
||||
false,
|
||||
"variables-before-functions"
|
||||
],
|
||||
"no-bitwise": false,
|
||||
"no-empty": false,
|
||||
"no-string-literal": false,
|
||||
"ordered-imports": false,
|
||||
"arrow-parens": [ true, "ban-single-arg-parens" ],
|
||||
"unified-signatures": false,
|
||||
"array-type": [ "array-simple" ],
|
||||
"ban-types": false,
|
||||
"max-classes-per-file": [ false ],
|
||||
"no-unused-expression": false,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-catch",
|
||||
"check-whitespace"
|
||||
],
|
||||
"object-literal-sort-keys": false,
|
||||
"trailing-comma": [
|
||||
true,
|
||||
{
|
||||
"singleline": "never",
|
||||
"multiline": "never"
|
||||
}
|
||||
],
|
||||
"variable-name": false,
|
||||
"no-reference": false,
|
||||
"curly": false,
|
||||
"no-console": [ false ],
|
||||
"prefer-conditional-expression": false,
|
||||
"no-empty-interface": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-this-assignment": false,
|
||||
"prefer-object-spread": false,
|
||||
"no-unnecessary-initializer": false,
|
||||
"prefer-for-of": false,
|
||||
"no-implicit-dependencies": [ "dev" ],
|
||||
"typeof-compare": false,
|
||||
"no-invalid-template-strings": false
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
Загрузка…
Ссылка в новой задаче