├── Comments.tmPreferences ├── Keymaps ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap └── Default (Windows).sublime-keymap ├── LICENSE ├── Main.sublime-menu ├── Menu └── Context.sublime-menu ├── README.md ├── Snippets ├── case_statement.sublime-snippet ├── class_definition.sublime-snippet ├── class_definition_extend.sublime-snippet ├── class_definition_implement.sublime-snippet ├── console_log.sublime-snippet ├── constructor_definition.sublime-snippet ├── export_class_definition.sublime-snippet ├── export_class_definition_extend.sublime-snippet ├── export_class_definition_implements.sublime-snippet ├── for_in.sublime-snippet ├── for_length.sublime-snippet ├── interface_definition.sublime-snippet ├── interface_definition_extend.sublime-snippet ├── method_definition.sublime-snippet ├── module_definition.sublime-snippet ├── private_method_definition.sublime-snippet ├── private_method_parameter.sublime-snippet ├── public_method_definition.sublime-snippet ├── public_method_parameter.sublime-snippet ├── reference.sublime-snippet ├── switch_case.sublime-snippet ├── variable_definition.sublime-snippet └── variable_definition_equals.sublime-snippet ├── TypeScript.JSON-tmLanguage ├── TypeScript.py ├── TypeScript.sublime-commands ├── TypeScript.sublime-settings ├── TypeScript.tmLanguage ├── changelogs ├── 0.9.md └── 1.0.0.md ├── messages.json ├── package.json └── sourcemap ├── __init__.py ├── decoder.py ├── exceptions.py └── objects.py /Comments.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Comments 7 | scope 8 | source.ts 9 | settings 10 | 11 | shellVariables 12 | 13 | 14 | name 15 | TM_COMMENT_START 16 | value 17 | // 18 | 19 | 20 | name 21 | TM_COMMENT_START_2 22 | value 23 | /* 24 | 25 | 26 | name 27 | TM_COMMENT_END_2 28 | value 29 | */ 30 | 31 | 32 | 33 | uuid 34 | 8d781b20-0d31-11e3-80a8-705681c17b97 35 | 36 | -------------------------------------------------------------------------------- /Keymaps/Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["alt+shift+s"], "command": "check_code_syntax"} 3 | , {"keys": ["alt+shift+c"], "command": "compile_code"} 4 | , {"keys": ["alt+shift+d"], "command": "compile_and_display_code", "args": {"opt": "-p"}} 5 | , {"keys": ["alt+shift+l"], "command": "compile_and_display_code", "args": {"opt": "-t"}} 6 | , {"keys": ["alt+shift+n"], "command": "compile_and_display_code", "args": {"opt": "-n"}} 7 | , {"keys": ["alt+shift+w"], "command": "toggle_watch_mode"} 8 | ] 9 | -------------------------------------------------------------------------------- /Keymaps/Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["alt+shift+s"], "command": "check_code_syntax"} 3 | , {"keys": ["alt+shift+c"], "command": "compile_code"} 4 | , {"keys": ["alt+shift+d"], "command": "compile_and_display_code", "args": {"opt": "-p"}} 5 | , {"keys": ["alt+shift+x"], "command": "compile_and_display_code", "args": {"opt": "-t"}} 6 | , {"keys": ["alt+shift+n"], "command": "compile_and_display_code", "args": {"opt": "-n"}} 7 | , {"keys": ["alt+shift+w"], "command": "toggle_watch_mode"} 8 | ] 9 | -------------------------------------------------------------------------------- /Keymaps/Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["alt+shift+s"], "command": "check_code_syntax"} 3 | , {"keys": ["alt+shift+c"], "command": "compile_code"} 4 | , {"keys": ["alt+shift+d"], "command": "compile_and_display_code", "args": {"opt": "-p"}} 5 | , {"keys": ["alt+shift+l"], "command": "compile_and_display_code", "args": {"opt": "-t"}} 6 | , {"keys": ["alt+shift+n"], "command": "compile_and_display_code", "args": {"opt": "-n"}} 7 | , {"keys": ["alt+shift+w"], "command": "toggle_watch_mode"} 8 | ] 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Anton Lavrenov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences", 4 | "mnemonic": "n", 5 | "id": "preferences", 6 | "children": 7 | [ 8 | { 9 | "caption": "Package Settings", 10 | "mnemonic": "P", 11 | "id": "package-settings", 12 | "children": 13 | [ 14 | { 15 | "caption": "Better TypeScript", 16 | "children": 17 | [ 18 | { 19 | "command": "open_file", 20 | "args": {"file": "${packages}/Better TypeScript/TypeScript.sublime-settings"}, 21 | "caption": "Settings – Default" 22 | }, 23 | { 24 | "command": "open_file", 25 | "args": {"file": "${packages}/User/TypeScript.sublime-settings"}, 26 | "caption": "Settings – User" 27 | }, 28 | { 29 | "command": "open_file", 30 | "args": { 31 | "file": "${packages}/Better TypeScript/Keymaps/Default (Windows).sublime-keymap", 32 | "platform": "Windows" 33 | }, 34 | "caption": "Key Bindings – Default" 35 | }, 36 | { 37 | "caption": "Key Bindings – User", 38 | "command": "open_file", "args": 39 | { 40 | "file": "${packages}/User/Default (Windows).sublime-keymap", 41 | "platform": "Windows" 42 | } 43 | }, 44 | { 45 | "command": "open_file", 46 | "args": { 47 | "file": "${packages}/Better TypeScript/Keymaps/Default (OSX).sublime-keymap", 48 | "platform": "OSX" 49 | }, 50 | "caption": "Key Bindings – Default" 51 | }, 52 | { 53 | "caption": "Key Bindings – User", 54 | "command": "open_file", "args": 55 | { 56 | "file": "${packages}/User/Default (OSX).sublime-keymap", 57 | "platform": "OSX" 58 | } 59 | }, 60 | { 61 | "command": "open_file", 62 | "args": { 63 | "file": "${packages}/Better TypeScript/Keymaps/Default (Linux).sublime-keymap", 64 | "platform": "Linux" 65 | }, 66 | "caption": "Key Bindings – Default" 67 | }, 68 | { 69 | "caption": "Key Bindings – User", 70 | "command": "open_file", "args": 71 | { 72 | "file": "${packages}/User/Default (Linux).sublime-keymap", 73 | "platform": "Linux" 74 | } 75 | }, 76 | { "caption": "-" } 77 | ] 78 | } 79 | ] 80 | } 81 | ] 82 | } 83 | ] 84 | -------------------------------------------------------------------------------- /Menu/Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Better TypeScript", 4 | "children": [ 5 | { 6 | "caption": "Check Syntax", 7 | "command": "check_code_syntax" 8 | }, 9 | { 10 | "caption": "Compile File", 11 | "command": "compile_code" 12 | }, 13 | { 14 | "caption": "Compile and Display JavaScript", 15 | "command": "compile_and_display_code", 16 | "args": { 17 | "opt": "-p" 18 | } 19 | }, 20 | { 21 | "caption": "Toggle Watch Mode", 22 | "command": "toggle_watch_mode" 23 | } 24 | ] 25 | } 26 | ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Better Typescript 2 | ================================ 3 | 4 | # Overview 5 | 6 | **This plugin is deprecated. Use [Official Type​Script plugin](https://packagecontrol.io/packages/TypeScript) instead.**. 7 | 8 | ## Description 9 | 10 | This is fork of [Better CoffeeScript](https://github.com/aponxi/sublime-better-coffeescript) but adopted for work with Typescript. 11 | Also look at this TypeScript plugin for Sublime Text https://github.com/Railk/T3S. It is really awesome. 12 | 13 | # Installation 14 | 15 | If you have Sublime Package Control, you know what to do. If not, well: it's a package manager for Sublime Text 3; it's awesome and you can [read about it here](https://sublime.wbond.net/). Installation guide can be [found here](https://sublime.wbond.net/installation). 16 | 17 | * Open the Command Pallete (`ctrl+shift+P` or `cmd+shift+P`). 18 | * Type "Install Package" and hit return. 19 | * Type "Better TypeScript" and hit return. 20 | 21 | # Build File Example 22 | 23 | Current package don't have sublime build file. You can create it by yourself and save it (`Preferences - Browse Packages... - User folder`) as `Typescript.sublime-build`. Then use `Cmd + B` to build your file. 24 | 25 | ``` 26 | { 27 | "cmd": ["tsc", "-d", "-m", "amd", "--sourcemap", "$file"], 28 | "file_regex": "(.*\\.ts?)\\s\\(([0-9]+)\\,([0-9]+)\\)\\:\\s(...*?)$", 29 | "selector": "source.ts", 30 | "osx": { 31 | "path": "/usr/local/bin:/opt/local/bin" 32 | }, 33 | "windows": { 34 | "cmd": ["tsc.cmd", "-d", "-m", "amd", "--sourcemap", "$file"] 35 | } 36 | } 37 | ``` 38 | 39 | # Commands/Shortcuts 40 | 41 | You can access the commands either using the command palette (`ctrl+shift+P` or `cmd+shift+P`) or via shortcuts. 42 | 43 | alt+shift+s - Run a syntax check 44 | alt+shift+c - Compile a file 45 | alt+shift+d - Display compiled JavaScript 46 | alt+shift+w - Toggle watch mode 47 | 48 | 49 | Context menu has `Compile Output` that compiles the current TypeScript and outputs the javascript code that is run, in a panel. 50 | 51 | **Note:** Some of the commands use the Status Bar for output, so you'll probably want to enable it (`View » Show Status Bar`). 52 | 53 | 54 | # Snippets 55 | 56 | - Use `TAB` to run a snippet after typing the trigger. 57 | - Use `TAB` and `shift+TAB` to cycle forward/backward through fields. 58 | - Use `ESC` to exit snippet mode. 59 | 60 | Thanks @MattSeen to provide Snippets (https://github.com/MattSeen/Sublime-TypeScript-Snippets) 61 | 62 | # Settings 63 | 64 | Go to `Preferences > Package Settings > Better TypeScript > Settings - User` to change settings. 65 | 66 | See `Preferences > Package Settings > Better TypeScript > Settings - Default` to see all available settings. 67 | 68 | 69 | # FAQ 70 | 71 | Most of the linux terminal commands written here can be run via [cygwin](http://cygwin.com/install.html) - aka Linux Terminal in Windows. 72 | 73 | - Most of the problems are related to configurations. Remember to configure `binDir` after you install! 74 | 75 | 76 | - Do I have `tsc` installed? 77 | 78 | Try finding tsc in your global npm list with `npm ls -g | grep tsc` which will output something like: 79 | 80 | ```bash 81 | npm ls -g | grep tsc 82 | ``` 83 | 84 | 85 | - Where can I find out the path to tsc binary? 86 | 87 | In Linux `which` command will tell you where a command originates from. In terminal type: 88 | 89 | ```bash 90 | which tsc 91 | # /usr/bin/tsc 92 | ``` 93 | 94 | This path will go into the `binDir` setting. 95 | -------------------------------------------------------------------------------- /Snippets/case_statement.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | case 10 | 11 | source.ts 12 | 13 | -------------------------------------------------------------------------------- /Snippets/class_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | class-default 14 | 15 | source.ts 16 | 17 | -------------------------------------------------------------------------------- /Snippets/class_definition_extend.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | class-default-extend 14 | 15 | source.ts 16 | 17 | -------------------------------------------------------------------------------- /Snippets/class_definition_implement.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | class-default-implements 14 | 15 | source.ts 16 | 17 | -------------------------------------------------------------------------------- /Snippets/console_log.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | log 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /Snippets/constructor_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | constructor 11 | 12 | source.ts 13 | 14 | -------------------------------------------------------------------------------- /Snippets/export_class_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | class-export 13 | 14 | source.ts 15 | 16 | -------------------------------------------------------------------------------- /Snippets/export_class_definition_extend.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | class-export-extend 14 | 15 | source.ts 16 | 17 | -------------------------------------------------------------------------------- /Snippets/export_class_definition_implements.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | class-export-implements 14 | 15 | source.ts 16 | 17 | -------------------------------------------------------------------------------- /Snippets/for_in.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | for-in 9 | 10 | source.ts 11 | 12 | -------------------------------------------------------------------------------- /Snippets/for_length.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | for-length 9 | 10 | source.ts 11 | 12 | -------------------------------------------------------------------------------- /Snippets/interface_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | interface-default 9 | 10 | source.ts 11 | 12 | -------------------------------------------------------------------------------- /Snippets/interface_definition_extend.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | interface-extend 9 | 10 | source.ts 11 | 12 | -------------------------------------------------------------------------------- /Snippets/method_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | method 11 | 12 | source.ts 13 | 14 | -------------------------------------------------------------------------------- /Snippets/module_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | module 9 | 10 | source.ts 11 | 12 | -------------------------------------------------------------------------------- /Snippets/private_method_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | private-method 11 | 12 | source.ts 13 | 14 | -------------------------------------------------------------------------------- /Snippets/private_method_parameter.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | parameter-method-private 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /Snippets/public_method_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | public-method 11 | 12 | source.ts 13 | 14 | -------------------------------------------------------------------------------- /Snippets/public_method_parameter.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | parameter-method-public 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /Snippets/reference.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 4 | ]]> 5 | 6 | reference 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /Snippets/switch_case.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | switch 17 | 18 | source.ts 19 | 20 | -------------------------------------------------------------------------------- /Snippets/variable_definition.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | var 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /Snippets/variable_definition_equals.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | var-equals 7 | 8 | source.ts 9 | 10 | -------------------------------------------------------------------------------- /TypeScript.JSON-tmLanguage: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TypeScript", 3 | "scopeName": "source.ts", 4 | "fileTypes": ["ts"], 5 | "patterns": [ 6 | { "include": "#shebang" }, 7 | { "include": "#expression" } 8 | ], 9 | 10 | "repository": { 11 | "shebang": { 12 | "comment": "node.js shebang", 13 | "name": "comment.line.ts", 14 | "match": "^#![\\S]+ node" 15 | }, 16 | 17 | 18 | 19 | "string-quoted-single": { 20 | "name": "string.quoted.single.ts", 21 | "begin": "'", 22 | "end": "'", 23 | "beginCaptures": { 24 | "0": { "name": "punctuation.definition.string.begin.ts" } 25 | }, 26 | "endCaptures": { 27 | "0": { "name": "punctuation.definition.string.end.ts" } 28 | }, 29 | "patterns": [ 30 | { 31 | "name": "constant.character.escape.ts", 32 | "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)" 33 | } 34 | ] 35 | }, 36 | "string-quoted-double": { 37 | "name": "string.quoted.double.ts", 38 | "begin": "\"", 39 | "end": "\"", 40 | "beginCaptures": { 41 | "0": { "name": "punctuation.definition.string.begin.ts" } 42 | }, 43 | "endCaptures": { 44 | "0": { "name": "punctuation.definition.string.end.ts" } 45 | }, 46 | "patterns": [ 47 | { 48 | "name": "constant.character.escape.ts", 49 | "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)" 50 | } 51 | ] 52 | }, 53 | "string": { 54 | "name": "string.ts", 55 | "patterns": [ 56 | { "include": "#string-quoted-single" }, 57 | { "include": "#string-quoted-double" } 58 | ] 59 | }, 60 | 61 | 62 | 63 | "regexp": { 64 | "begin": "(?<=[=(:]|^|return|&&|\\|\\||!)\\s*(/)(?![/*+{}?])", 65 | "end": "(/)[igm]*", 66 | "name": "string.regexp.ts", 67 | "endCaptures": { 68 | "1": { "name": "punctuation.definition.string.end.ts" } 69 | }, 70 | "beginCaptures": { 71 | "1": { "name": "punctuation.definition.string.begin.ts" } 72 | }, 73 | "patterns": [ 74 | { 75 | "name": "constant.character.escape.ts", 76 | "match": "\\\\." 77 | } 78 | ] 79 | }, 80 | 81 | 82 | 83 | "comment-block-doc": { 84 | "name": "comment.block.documentation.ts", 85 | "begin": "/\\*\\*(?!/)", 86 | "end": "\\*/", 87 | "captures": { 88 | "0": { "name": "punctuation.definition.comment.ts" } 89 | } 90 | }, 91 | "comment-block": { 92 | "name": "comment.block.ts", 93 | "begin": "/\\*", 94 | "end": "\\*/", 95 | "captures": { 96 | "0": { "name": "punctuation.definition.comment.ts" } 97 | } 98 | }, 99 | "comment-block-html": { 100 | "name": "comment.block.html.js", 101 | "match": "()", 102 | "captures": { 103 | "0": { "name": "punctuation.definition.comment.html.js" }, 104 | "2": { "name": "punctuation.definition.comment.html.js" } 105 | } 106 | }, 107 | "comment-line": { 108 | "name": "comment.line.double-slash.ts", 109 | "match": "(//).*$\n?", 110 | "captures": { 111 | "1": { "name": "punctuation.definition.comment.ts" } 112 | } 113 | }, 114 | "comment": { 115 | "name": "comment.ts", 116 | "patterns": [ 117 | { "include": "#comment-block-doc" }, 118 | { "include": "#comment-block" }, 119 | { "include": "#comment-block-html" }, 120 | { "include": "#comment-line" } 121 | ] 122 | }, 123 | 124 | 125 | 126 | "block-braces-round": { 127 | "name": "meta.expression.braces.round", 128 | "begin": "\\(", 129 | "end": "\\)", 130 | "beginCaptures": { 131 | "0": { "name": "meta.brace.round.ts" } 132 | }, 133 | "endCaptures": { 134 | "0": { "name": "meta.brace.round.ts" } 135 | }, 136 | "patterns": [ 137 | { "include": "#expression" } 138 | ] 139 | }, 140 | "block-braces-curly": { 141 | "name": "meta.expression.braces.curly", 142 | "begin": "\\{", 143 | "end": "\\}", 144 | "beginCaptures": { 145 | "0": { "name": "meta.brace.curly.ts" } 146 | }, 147 | "endCaptures": { 148 | "0": { "name": "meta.brace.curly.ts" } 149 | }, 150 | "patterns": [ 151 | { "include": "#expression" } 152 | ] 153 | }, 154 | "block-braces-square": { 155 | "name": "meta.expression.braces.square", 156 | "begin": "\\[", 157 | "end": "\\]", 158 | "beginCaptures": { 159 | "0": { "name": "meta.brace.square.ts" } 160 | }, 161 | "endCaptures": { 162 | "0": { "name": "meta.brace.square.ts" } 163 | }, 164 | "patterns": [ 165 | { "include": "#expression" } 166 | ] 167 | }, 168 | "block": { 169 | "name": "block.ts", 170 | "patterns": [ 171 | { "include": "#block-braces-curly" }, 172 | { "include": "#block-braces-round" }, 173 | { "include": "#block-braces-square" } 174 | ] 175 | }, 176 | 177 | 178 | 179 | "module-expression": { 180 | "name": "meta.module.ts", 181 | "begin": "\\b(module)\\b(?:\\s+([a-zA-Z_$][\\w$]*))?", 182 | "end": "(?=\\})", 183 | "beginCaptures": { 184 | "1": { "name": "storage.type.module.ts" }, 185 | "2": { "name": "entity.name.type.module.ts" } 186 | }, 187 | "endCaptures": { 188 | "0": { "name": "meta.brace.curly.ts" } 189 | }, 190 | "patterns": [ 191 | { "include": "#expression" } 192 | ] 193 | }, 194 | 195 | "class-expression": { 196 | "name": "meta.class.ts", 197 | "begin": "\\b(class|interface)\\b(?:\\s+([a-zA-Z_$][\\w$]*))?", 198 | "end": "(?=\\})", 199 | "beginCaptures": { 200 | "1": { "name": "storage.type.class.ts" }, 201 | "2": { "name": "entity.name.type.class.ts" } 202 | }, 203 | "endCaptures": { 204 | "0": { "name": "meta.brace.curly.ts" } 205 | }, 206 | "patterns": [ 207 | { "include": "#comment" }, 208 | { "include": "#meta-class-body" }, 209 | { "include": "#expression" } 210 | ] 211 | }, 212 | "meta-storage-modifier": { 213 | "name": "storage.modifier.ts", 214 | "match": "\\b(const|export|extends|final|implements|native|private|protected|public|static|synchronized|throws|transient|volatile)\\b" 215 | }, 216 | "meta-variable-type": { 217 | "begin":":", 218 | "end": "(?=[,);=])", 219 | "patterns": [ 220 | { "include": "#expression" } 221 | ] 222 | }, 223 | "meta-variable-initializer": { 224 | "begin": "(=)", 225 | "end": "(?=[,);=])", 226 | "beginCaptures": { 227 | "1": { "name": "keyword.operator.ts" } 228 | }, 229 | "patterns": [ 230 | { "include": "#expression" } 231 | ] 232 | }, 233 | "meta-class-body": { 234 | "name": "meta.expression.body.class", 235 | "begin": "\\{", 236 | "end": "(?=\\})", 237 | "beginCaptures": { 238 | "0": { "name": "meta.brace.curly.ts" } 239 | }, 240 | "endCaptures": {}, 241 | "patterns": [ 242 | { "include": "#comment" }, 243 | { "include": "#meta-storage-modifier" }, 244 | { "include": "#meta-class-member-attribute" }, 245 | { "include": "#meta-class-member-method" } 246 | ] 247 | }, 248 | "meta-class-member-attribute": { 249 | "begin": "\\b([a-zA-Z_$][\\w$]*)\\s*(?=(=|:))", 250 | "end": "(;)", 251 | "beginCaptures": { 252 | "1": { "name": "meta.toc-list.class.member.ts" } 253 | }, 254 | "endCaptures": { 255 | "1": { "name": "punctuation.terminator.statement.ts" } 256 | }, 257 | "patterns": [ 258 | { "include": "#meta-variable-type" }, 259 | { "include": "#meta-variable-initializer" } 260 | ] 261 | }, 262 | "meta-class-member-method": { 263 | "name": "meta.class.member.ts", 264 | "begin": "\\b(?:(get|set)\\s+)?([a-zA-Z_$][\\w$]*)\\s*(?=\\()", 265 | "end": "(\\})|(;)", 266 | "beginCaptures": { 267 | "1": { "name": "storage.type.property.ts" }, 268 | "2": { "name": "entity.name.function.ts" } 269 | }, 270 | "endCaptures": { 271 | "1": { "name": "meta.brace.curly.ts" }, 272 | "2": { "name": "punctuation.terminator.statement.ts" } 273 | }, 274 | "patterns": [ 275 | { "include": "#comment" }, 276 | { "include": "#meta-function-parameters" }, 277 | { "include": "#misc-higlighting" }, 278 | { "include": "#meta-function-body" } 279 | ] 280 | }, 281 | 282 | "meta-function-parameters": { 283 | "name": "meta.expression.body.class", 284 | "begin": "\\(", 285 | "end": "\\)", 286 | "beginCaptures": { 287 | "0": { "name": "punctuation.definition.parameters.begin.ts" } 288 | }, 289 | "endCaptures": { 290 | "0": { "name": "punctuation.definition.parameters.end.ts" } 291 | }, 292 | "patterns": [ 293 | { "include": "#comment" }, 294 | { "include": "#meta-storage-modifier" }, 295 | { 296 | "name": "variable.parameter.function.ts", 297 | "match": "[a-zA-Z_$][\\w$]*" 298 | }, 299 | { "include": "#meta-variable-type" }, 300 | { "include": "#meta-variable-initializer" } 301 | ] 302 | }, 303 | "meta-function-body": { 304 | "name": "meta.expression.body.function", 305 | "begin": "\\{", 306 | "end": "(?=\\})", 307 | "beginCaptures": { 308 | "0": { "name": "meta.brace.curly.ts" } 309 | }, 310 | "endCaptures": { 311 | "0": { "name": "meta.brace.curly.ts" } 312 | }, 313 | "patterns": [ 314 | { "include": "#expression" } 315 | ] 316 | }, 317 | "meta-function-assignment": { 318 | "match": "\\b([a-zA-Z_$][\\w$]*)\\s*(?:(=)|:)\\s*(?=(\\bfunction\\b))", 319 | "captures": { 320 | "1": { "name": "entity.name.function.ts" }, 321 | "2": { "name": "keyword.operator.ts" } 322 | } 323 | }, 324 | 325 | "meta-function-assignment-quoted": { 326 | "match": "(?:((')([^']*)('))|((\")([^\"]+)(\")))\\s*:\\s*(?=\\bfunction\\b)", 327 | "captures": { 328 | "1": { "name": "string.quoted.single.ts" }, 329 | "2": { "name": "punctuation.definition.string.begin.ts" }, 330 | "3": { "name": "entity.name.function.ts" }, 331 | "4": { "name": "punctuation.definition.string.end.ts" }, 332 | "5": { "name": "string.quoted.double.ts" }, 333 | "6": { "name": "punctuation.definition.string.begin.ts" }, 334 | "7": { "name": "entity.name.function.ts" }, 335 | "8": { "name": "punctuation.definition.string.end.ts" } 336 | } 337 | }, 338 | "meta-function": { 339 | "begin": "\\b(function)(?:\\s+([a-zA-Z_$][\\w$]*))?\\s*", 340 | "end": "(\\})|(;)", 341 | "beginCaptures": { 342 | "1": { "name": "storage.type.property.ts" }, 343 | "2": { "name": "entity.name.function.ts" } 344 | }, 345 | "beginCaptures": { 346 | "0": { "name": "meta.function.ts" }, 347 | "1": { "name": "storage.type.function.ts" }, 348 | "2": { "name": "entity.name.function.ts" } 349 | }, 350 | "endCaptures": { 351 | "0": { "name": "meta.brace.curly.ts" } 352 | }, 353 | "patterns": [ 354 | { "include": "#comment" }, 355 | { "include": "#meta-function-parameters" }, 356 | { "include": "#meta-function-body" }, 357 | { "include": "#misc-higlighting" } 358 | ] 359 | }, 360 | "function": { 361 | "name": "meta.function.ts", 362 | "patterns": [ 363 | { "include": "#meta-function-assignment" }, 364 | { "include": "#meta-function-assignment-quoted" }, 365 | { "include": "#meta-function" } 366 | ] 367 | }, 368 | 369 | 370 | "misc-higlighting": { 371 | "name": "misc.ts", 372 | "comment": "This patterns are not affecting scope rules and are usefull for higlighting purposes only", 373 | "patterns": [ 374 | { 375 | "name": "meta.class.instance.constructor", 376 | "match": "(new)\\s+(\\w+(?:\\.[\\w$]*)*)", 377 | "captures": { 378 | "1": { "name": "keyword.operator.new.ts" }, 379 | "2": { "name": "entity.name.type.instance.ts" } 380 | } 381 | }, 382 | { 383 | "name": "meta.object.ts.firebug", 384 | "match": "\\b(console)\\.(warn|info|log|error|time|timeEnd|assert)\\b", 385 | "captures": { 386 | "1": { "name": "entity.name.type.object.ts.firebug" }, 387 | "2": { "name": "support.function.ts.firebug" } 388 | } 389 | }, 390 | { 391 | "name": "entity.name.type.object.ts.firebug", 392 | "match": "\\b(console)\\b" 393 | }, 394 | { 395 | "name": "constant.numeric.ts", 396 | "match": "\\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\\.[0-9]+)?))\\b" 397 | }, 398 | { 399 | "name": "storage.type.ts", 400 | "match": "\\b(boolean|byte|char|class|double|enum|float|function|int|interface|long|number|short|string|var|void)\\b" 401 | }, 402 | { 403 | "include": "#meta-storage-modifier" 404 | }, 405 | { 406 | "name": "keyword.control.ts", 407 | "match": "\\b(break|case|catch|continue|declare|default|do|else|finally|for|goto|if|import|package|return|switch|throw|try|while)\\b" 408 | }, 409 | { 410 | "name": "keyword.operator.ts", 411 | "match": "\\b(delete|in|instanceof|new|typeof|with)\\b" 412 | }, 413 | { 414 | "name": "constant.language.boolean.true.ts", 415 | "match": "\\btrue\\b" 416 | }, 417 | { 418 | "name": "constant.language.boolean.false.ts", 419 | "match": "\\bfalse\\b" 420 | }, 421 | { 422 | "name": "constant.language.null.ts", 423 | "match": "\\bnull\\b" 424 | }, 425 | { 426 | "name": "support.constant.ts", 427 | "match": "\\b(super|this)\\b" 428 | }, 429 | { 430 | "name": "meta.prototype.ts", 431 | "match": "(\\.)(prototype|__proto__)\\b", 432 | "captures": { 433 | "1": { "name": "meta.delimiter.method.period.ts" }, 434 | "2": { "name": "support.constant.ts" } 435 | } 436 | }, 437 | { 438 | "name": "keyword.other.ts", 439 | "match": "\\b(debugger)\\b" 440 | }, 441 | { 442 | "name": "support.class.ts", 443 | "match": "\\b(Anchor|Applet|Area|Array|Boolean|Button|Checkbox|Date|document|event|FileUpload|Form|Frame|Function|Hidden|History|Image|JavaArray|JavaClass|JavaObject|JavaPackage|java|Layer|Link|Location|Math|MimeType|Number|navigator|netscape|Object|Option|Packages|Password|Plugin|Radio|RegExp|Reset|Select|String|Style|Submit|screen|sun|Text|Textarea|window|XMLHttpRequest)\\b" 444 | }, 445 | { 446 | "name": "support.function.ts", 447 | "match": "\\b(require|module\\.exports|module\\.id|exports)\\b" 448 | }, 449 | { 450 | "name": "support.function.ts", 451 | "match": "\\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack))\\b(?=\\()" 452 | }, 453 | { 454 | "name": "support.function.dom.ts", 455 | "match": "\\b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\\b(?=\\()" 456 | }, 457 | { 458 | "name": "support.constant.ts", 459 | "match": "(?<=\\.)(s(ystemLanguage|cr(ipts|ollbars|een(X|Y|Top|Left))|t(yle(Sheets)?|atus(Text|bar)?)|ibling(Below|Above)|ource|uffixes|e(curity(Policy)?|l(ection|f)))|h(istory|ost(name)?|as(h|Focus))|y|X(MLDocument|SLDocument)|n(ext|ame(space(s|URI)|Prop))|M(IN_VALUE|AX_VALUE)|c(haracterSet|o(n(structor|trollers)|okieEnabled|lorDepth|mp(onents|lete))|urrent|puClass|l(i(p(boardData)?|entInformation)|osed|asses)|alle(e|r)|rypto)|t(o(olbar|p)|ext(Transform|Indent|Decoration|Align)|ags)|SQRT(1_2|2)|i(n(ner(Height|Width)|put)|ds|gnoreCase)|zIndex|o(scpu|n(readystatechange|Line)|uter(Height|Width)|p(sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(i(splay|alog(Height|Top|Width|Left|Arguments)|rectories)|e(scription|fault(Status|Ch(ecked|arset)|View)))|u(ser(Profile|Language|Agent)|n(iqueID|defined)|pdateInterval)|_content|p(ixelDepth|ort|ersonalbar|kcs11|l(ugins|atform)|a(thname|dding(Right|Bottom|Top|Left)|rent(Window|Layer)?|ge(X(Offset)?|Y(Offset)?))|r(o(to(col|type)|duct(Sub)?|mpter)|e(vious|fix)))|e(n(coding|abledPlugin)|x(ternal|pando)|mbeds)|v(isibility|endor(Sub)?|Linkcolor)|URLUnencoded|P(I|OSITIVE_INFINITY)|f(ilename|o(nt(Size|Family|Weight)|rmName)|rame(s|Element)|gColor)|E|whiteSpace|l(i(stStyleType|n(eHeight|kColor))|o(ca(tion(bar)?|lName)|wsrc)|e(ngth|ft(Context)?)|a(st(M(odified|atch)|Index|Paren)|yer(s|X)|nguage))|a(pp(MinorVersion|Name|Co(deName|re)|Version)|vail(Height|Top|Width|Left)|ll|r(ity|guments)|Linkcolor|bove)|r(ight(Context)?|e(sponse(XML|Text)|adyState))|global|x|m(imeTypes|ultiline|enubar|argin(Right|Bottom|Top|Left))|L(N(10|2)|OG(10E|2E))|b(o(ttom|rder(Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(Color|Image)))\\b" 460 | }, 461 | { 462 | "name": "support.constant.dom.ts", 463 | "match": "(?<=\\.)(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\\b" 464 | }, 465 | { 466 | "name": "support.constant.dom.ts", 467 | "match": "\\b(ELEMENT_NODE|ATTRIBUTE_NODE|TEXT_NODE|CDATA_SECTION_NODE|ENTITY_REFERENCE_NODE|ENTITY_NODE|PROCESSING_INSTRUCTION_NODE|COMMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE|DOCUMENT_FRAGMENT_NODE|NOTATION_NODE|INDEX_SIZE_ERR|DOMSTRING_SIZE_ERR|HIERARCHY_REQUEST_ERR|WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR)\\b" 468 | }, 469 | { 470 | "name": "support.function.event-handler.ts", 471 | "match": "\\bon(R(ow(s(inserted|delete)|e(nter|xit))|e(s(ize(start|end)?|et)|adystatechange))|Mouse(o(ut|ver)|down|up|move)|B(efore(cut|deactivate|u(nload|pdate)|p(aste|rint)|editfocus|activate)|lur)|S(croll|top|ubmit|elect(start|ionchange)?)|H(over|elp)|C(hange|ont(extmenu|rolselect)|ut|ellchange|l(ick|ose))|D(eactivate|ata(setc(hanged|omplete)|available)|r(op|ag(start|over|drop|en(ter|d)|leave)?)|blclick)|Unload|P(aste|ropertychange)|Error(update)?|Key(down|up|press)|Focus|Load|A(ctivate|fter(update|print)|bort))\\b" 472 | }, 473 | { 474 | "name": "keyword.operator.ts", 475 | "match": "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|(? 0: 192 | return text 193 | return Text.all(view) 194 | 195 | 196 | def popup_error_list(view, error_list): 197 | 198 | panel_items = [] 199 | 200 | for error in error_list: 201 | line_text = view.substr(view.full_line(view.text_point(error['line'], 0))) 202 | item = [error['message'], '{0}: {1}'.format(error['line'] + 1, line_text.strip())] 203 | panel_items.append(item) 204 | 205 | def on_done(selected_item): 206 | if selected_item == -1: 207 | return 208 | 209 | selected = view.sel() 210 | selected.clear() 211 | 212 | error = error_list[selected_item] 213 | region_begin = view.text_point(error['line'], error['col'] or 0) 214 | 215 | selected.add(sublime.Region(region_begin, region_begin)) 216 | # We have to force a move to update the cursor position 217 | view.run_command('move', {'by': 'characters', 'forward': True}) 218 | view.run_command('move', {'by': 'characters', 'forward': False}) 219 | view.show_at_center(region_begin) 220 | 221 | view.window().show_quick_panel(panel_items, on_done) 222 | 223 | 224 | class CompileCodeCommand(TextCommand): 225 | def is_enabled(self): 226 | return isTypescript(self.view) 227 | 228 | def on_done(self, result): 229 | if result['okay'] is True: 230 | status = 'Compilation Succeeded' 231 | else: 232 | status = 'Compilation FAILED ' 233 | error_list = [] 234 | print(result["err"]) 235 | for line in result["err"].split('\n'): 236 | if len(line.split(":")) < 3: 237 | continue 238 | try: 239 | message = line.split(":")[2] 240 | lineNum = line.split("(")[1].split(",")[0] 241 | rowNum = line.split("(")[1].split(",")[1].split(")")[0] 242 | except: 243 | print("Cannot parse: " + line) 244 | continue 245 | try: 246 | error_list.append({"message": message, "line": int(lineNum)-1, "col": int(rowNum)}) 247 | except: 248 | continue 249 | if len(error_list): 250 | popup_error_list(self.view, error_list) 251 | 252 | later = lambda: sublime.status_message(status) 253 | sublime.set_timeout(later, 300) 254 | 255 | def run(self, *args, **kwargs): 256 | # no_wrapper = settings_get('noWrapper', True) 257 | compile_dir = settings_get('compileDir') 258 | source_file = self.view.file_name() 259 | source_dir = os.path.normcase(os.path.dirname(source_file)) 260 | compile_paths = settings_get('compilePaths') 261 | sourcemaps = settings_get('sourceMaps', True) 262 | args = [source_file] 263 | if sourcemaps: 264 | args = ['--sourcemap'] + args 265 | 266 | # check instance of compile_paths 267 | if isinstance(compile_paths, dict): 268 | appendix_len = None 269 | for key_path in compile_paths: 270 | norm_path = os.path.normcase(key_path) 271 | appendix = os.path.relpath(source_dir, norm_path) 272 | if not appendix.startswith('..') and (appendix_len is None or len(appendix) < appendix_len): 273 | appendix_len = len(appendix) 274 | compile_dir = compile_paths[key_path] 275 | if not os.path.isabs(compile_dir): 276 | compile_dir = os.path.join(norm_path, compile_dir) 277 | compile_dir = os.path.join(compile_dir, appendix) 278 | 279 | if compile_dir and (isinstance(compile_dir, str)): 280 | # Check for absolute path or relative path for compile_dir 281 | if not os.path.isabs(compile_dir): 282 | compile_dir = os.path.join(source_dir, compile_dir) 283 | print("Compile to:" + compile_dir) 284 | # create folder if not exist 285 | if not os.path.exists(compile_dir): 286 | os.makedirs(compile_dir) 287 | print("Compile dir did not exist, created folder: " + compile_dir) 288 | folder, file_nm = os.path.split(source_file) 289 | args = ['--outDir', compile_dir] + args 290 | else: 291 | compile_dir = source_dir 292 | print("Compile to same directory") 293 | 294 | if sourcemaps: 295 | cwd = source_dir 296 | else: 297 | cwd = None 298 | later = lambda: sublime.status_message("Compiling") 299 | sublime.set_timeout(later, 300) 300 | run("tsc", args, cwd=cwd, callback=lambda res: self.on_done(res)) 301 | 302 | 303 | class CompileAndDisplayCodeCommand(TextCommand): 304 | def is_enabled(self): 305 | return isTypescript(self.view) 306 | 307 | def on_done(self, res, output): 308 | if res["okay"] is True: 309 | self.view.window().open_file(self.view.file_name().split(".")[0]+'.js') 310 | else: 311 | output = self.view.window().new_file() 312 | output.set_scratch(True) 313 | output.set_syntax_file('Packages/JavaScript/JavaScript.tmLanguage') 314 | output.run_command('update_watch', {'pos': 0, 'text': res["out"] or res["err"]}) 315 | sublime.status_message("Compiling done.") 316 | 317 | def run(self, edit, **kwargs): 318 | sublime.status_message("Compiling typescript...") 319 | args = [self.view.file_name()] 320 | run("tsc", args, callback=lambda res: self.on_done(res, edit)) 321 | 322 | 323 | class CheckCodeSyntaxCommand(TextCommand): 324 | def is_enabled(self): 325 | return isTypescript(self.view) 326 | 327 | def on_done(self, res): 328 | if res["okay"] is True: 329 | status = 'Valid' 330 | else: 331 | status = res["err"].split("\n")[0] 332 | sublime.message_dialog('Syntax %s' % status) 333 | # sublime.status_message() 334 | 335 | def run(self, edit): 336 | sublime.status_message("Checking syntax...") 337 | args = [self.view.file_name(), "--outDir", tempfile.gettempdir()] 338 | run("tsc", args, callback=lambda res: self.on_done(res)) 339 | 340 | 341 | class UpdateWatchCommand(sublime_plugin.TextCommand): 342 | def run(self, edit, pos, text): 343 | region = sublime.Region(0, self.view.size()) 344 | self.view.erase(edit, region) 345 | self.view.insert(edit, pos, text) 346 | 347 | watchers = {} 348 | 349 | 350 | def watched_filename(view): 351 | if view.file_name() is not None: 352 | filename = view.file_name().split('/')[-1] 353 | else: 354 | filename = "Unsaved File" 355 | return filename 356 | 357 | 358 | class Tool(): 359 | @staticmethod 360 | def get_file_name(file_path): 361 | if file_path: 362 | filename = os.path.split(file_path)[-1] 363 | else: 364 | filename = "Unsaved File" 365 | return filename 366 | 367 | @staticmethod 368 | def get_js_file_name(tsc_file_name): 369 | fileName, fileExtension = os.path.splitext(tsc_file_name) 370 | output_filename = fileName + '.js' 371 | return output_filename 372 | 373 | 374 | class Watcher(): 375 | def __init__(self, inputView): 376 | self.inputView = inputView 377 | print("Now watching " + watched_filename(inputView)) 378 | if self.inputView.window().num_groups() == 1: 379 | # create new column 380 | self.inputView.window().run_command('set_layout', { 381 | "cols": [0.0, 0.5, 1.0], 382 | "rows": [0.0, 1.0], 383 | "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] 384 | }) 385 | self.create_output() 386 | 387 | def on_done(self, res): 388 | if not res["okay"]: 389 | sublime.message_dialog("Error. See console.") 390 | print(res["err"]) 391 | return 392 | # create new tab 393 | self.outputView = self.inputView.window().open_file(self.outputFilePath) 394 | # move it to second column 395 | self.outputView.window().focus_group(1) 396 | self.outputView.window().set_view_index(self.outputView, self.outputView.window().active_group(), 0) 397 | # self.outputView.window().focus_group(0) 398 | self.inputView.window().focus_view(self.inputView) 399 | mapFile = self.sourceFilePath.split(".")[0]+'.js.map' 400 | (inputRow, inputCol) = self.inputView.rowcol(self.inputView.sel()[0].begin()) 401 | index = load(open(mapFile)).getpos(line=inputRow, column=inputCol) 402 | if not index: 403 | return 404 | (row, col) = index 405 | row = int(row) 406 | def goto(): 407 | selected = self.outputView.sel() 408 | selected.clear() 409 | region_begin = self.outputView.text_point(row, 0) 410 | selected.add(sublime.Region(region_begin, region_begin)) 411 | self.outputView.run_command('move', {'by': 'characters', 'forward': True}) 412 | self.outputView.run_command('move', {'by': 'characters', 'forward': False}) 413 | self.outputView.show_at_center(region_begin) 414 | sublime.set_timeout(goto, 10) 415 | 416 | def create_output(self): 417 | self.sourceFilePath = self.inputView.file_name() 418 | self.outputFileName = Tool.get_js_file_name(Tool.get_file_name(self.sourceFilePath)) 419 | self.outputFilePath = path.join(path.dirname(self.sourceFilePath), self.outputFileName) 420 | args = ["--sourcemap", self.sourceFilePath] 421 | run("tsc", args, callback=lambda res: self.on_done(res)) 422 | 423 | def refresh(self): 424 | args = ["--sourcemap", self.sourceFilePath] 425 | run("tsc", args, callback=lambda res: self.on_done(res)) 426 | 427 | def stop(self): 428 | if not self.inputView.id() in watchers: 429 | return 430 | print("Stop watching: " + self.inputView.file_name()) 431 | del watchers[self.inputView.id()] 432 | window = self.outputView.window() or self.inputView.window() 433 | if self.outputView.window(): 434 | window.focus_view(self.outputView) 435 | window.run_command("close") 436 | 437 | if len(watchers) == 0 and len(window.views_in_group(1)) == 0: 438 | window.run_command('set_layout', { 439 | "cols": [0.0, 1.0], 440 | "rows": [0.0, 1.0], 441 | "cells": [[0, 0, 1, 1]] 442 | }) 443 | 444 | 445 | class ToggleWatchModeCommand(TextCommand): 446 | views = {} 447 | outputs = {} 448 | 449 | def is_enabled(self): 450 | return isTypescript(self.view) 451 | 452 | def run(self, edit): 453 | viewID = self.view.id() 454 | if not viewID in watchers: 455 | watchers[viewID] = Watcher(self.view) 456 | else: 457 | watchers[viewID].stop() 458 | 459 | 460 | class CaptureEditing(sublime_plugin.EventListener): 461 | 462 | def is_enabled(self, view): 463 | return isTypescript(view) 464 | 465 | def handleTimeout(self, watcher): 466 | if self._new_modify and not self._refreshed: 467 | sublime.set_timeout(functools.partial(self.handleTimeout, watcher), 1000) 468 | self._new_modify = False 469 | else: 470 | if self._refreshed: 471 | return 472 | self._refreshed = True 473 | watcher.refresh() 474 | 475 | def on_modified(self, view): 476 | if not self.is_enabled(view): 477 | return 478 | viewID = view.id() 479 | self._new_modify = True 480 | if viewID in watchers: 481 | self._refreshed = False 482 | self.handleTimeout(watchers[viewID]) 483 | 484 | def on_post_save(self, view): 485 | if not self.is_enabled(view): 486 | return 487 | compile_on_save = settings_get('compileOnSave', True) 488 | if compile_on_save is True: 489 | print("Compiling on save...") 490 | view.run_command("compile_code") 491 | 492 | if settings_get('lintOnSave', True) is True: 493 | view.run_command("lint_code") 494 | 495 | watch_save = settings_get('watchOnSave', True) 496 | if watch_save: 497 | viewID = view.id() 498 | if viewID in watchers: 499 | watchers[viewID].refresh() 500 | 501 | def on_close(self, view): 502 | viewID = view.id() 503 | for k, watcher in watchers.items(): 504 | if watcher.outputView.id() == viewID: 505 | watcher.stop() 506 | break 507 | 508 | if not self.is_enabled(view): 509 | return 510 | 511 | if viewID in watchers: 512 | watchers[viewID].stop() 513 | -------------------------------------------------------------------------------- /TypeScript.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "TypeScript: Check Syntax" 4 | , "command": "check_code_syntax" 5 | } 6 | , { 7 | "caption": "TypeScript: Compile File" 8 | , "command": "compile_code" 9 | } 10 | , { 11 | "caption": "TypeScript: Display JavaScript" 12 | , "command": "compile_and_display_code", "args": {"opt": "-p"} 13 | } 14 | , { 15 | "caption": "TypeScript: Toggle Watch Mode" 16 | , "command": "toggle_watch_mode" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /TypeScript.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | /* 3 | The directories you would like to include in $PATH environment variable. 4 | Use this if your node installation is at a seperate location and getting errors such as `cannot find node executable` 5 | 6 | example: 7 | "envPATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 8 | 9 | */ 10 | "envPATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 11 | /* 12 | The directory containing your tsc binary. Usually 13 | /usr/local/bin or /usr/bin. 14 | */ 15 | "binDir": "/usr/bin", 16 | /* 17 | Enable or disable refresh the compiled Output on Save. 18 | Only available for watch mode. 19 | */ 20 | "watchOnSave": true, 21 | /* 22 | Enable Compiling on save. It will compile into the same folder. 23 | */ 24 | "compileOnSave": false, 25 | /* 26 | ## Enable compiling to a specific directory. 27 | #### Description 28 | 29 | if it is a string like 'some/directory' then `-o some/directory` will be added to `tsc` compiler. 30 | if it is false or not string then it will compile your `script.tsc` to the directory it is in. 31 | 32 | #### Example: 33 | Directory is relative to the file you are editing if specified such as 34 | compileDir": "out" 35 | Directory is absolute if specified such as 36 | compileDir": "/home/logan/Desktop/out" 37 | 38 | */ 39 | "compileDir": false, 40 | /* 41 | ## Enable compiling to a specific relative directories. 42 | 43 | #### Example: 44 | Set absolute path for compile dir: 45 | "compileDir": "/home/user/projects/js" 46 | And specified folders 47 | "relativeDir": "/home/user/projects/tsc" 48 | "compilePaths": 49 | { 50 | "/home/user/projects/tsc": "/home/user/projects/first/js", 51 | "/home/user/projects/second/tsc": "../js", 52 | } 53 | 54 | So 55 | "/home/user/projects/tsc/app.tsc" will compile to "/home/user/projects/first/js/app.js" 56 | "/home/user/projects/tsc/models/prod.tsc" will compile to "/home/user/projects/first/js/models/prod.js" 57 | "/home/user/projects/tsc/second/tsc/app2.tsc" will compile to "/home/user/projects/second/js/app2.js" 58 | "/home/user/projects/main.tsc" will compile to "/home/user/projects/js/main.js" 59 | 60 | */ 61 | "compilePaths": false, 62 | 63 | /* COMPILE OPTIONS */ 64 | /* 65 | ## Enable source maps support 66 | */ 67 | "sourceMaps":false, 68 | "target" : "ES3", 69 | "noImplicitAny" : false 70 | } 71 | -------------------------------------------------------------------------------- /TypeScript.tmLanguage: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | fileTypes 6 | 7 | ts 8 | 9 | name 10 | TypeScript 11 | patterns 12 | 13 | 14 | include 15 | #shebang 16 | 17 | 18 | include 19 | #expression 20 | 21 | 22 | repository 23 | 24 | block 25 | 26 | name 27 | block.ts 28 | patterns 29 | 30 | 31 | include 32 | #block-braces-curly 33 | 34 | 35 | include 36 | #block-braces-round 37 | 38 | 39 | include 40 | #block-braces-square 41 | 42 | 43 | 44 | block-braces-curly 45 | 46 | begin 47 | \{ 48 | beginCaptures 49 | 50 | 0 51 | 52 | name 53 | meta.brace.curly.ts 54 | 55 | 56 | end 57 | \} 58 | endCaptures 59 | 60 | 0 61 | 62 | name 63 | meta.brace.curly.ts 64 | 65 | 66 | name 67 | meta.expression.braces.curly 68 | patterns 69 | 70 | 71 | include 72 | #expression 73 | 74 | 75 | 76 | block-braces-round 77 | 78 | begin 79 | \( 80 | beginCaptures 81 | 82 | 0 83 | 84 | name 85 | meta.brace.round.ts 86 | 87 | 88 | end 89 | \) 90 | endCaptures 91 | 92 | 0 93 | 94 | name 95 | meta.brace.round.ts 96 | 97 | 98 | name 99 | meta.expression.braces.round 100 | patterns 101 | 102 | 103 | include 104 | #expression 105 | 106 | 107 | 108 | block-braces-square 109 | 110 | begin 111 | \[ 112 | beginCaptures 113 | 114 | 0 115 | 116 | name 117 | meta.brace.square.ts 118 | 119 | 120 | end 121 | \] 122 | endCaptures 123 | 124 | 0 125 | 126 | name 127 | meta.brace.square.ts 128 | 129 | 130 | name 131 | meta.expression.braces.square 132 | patterns 133 | 134 | 135 | include 136 | #expression 137 | 138 | 139 | 140 | class-expression 141 | 142 | begin 143 | \b(class|interface)\b(?:\s+([a-zA-Z_$][\w$]*))? 144 | beginCaptures 145 | 146 | 1 147 | 148 | name 149 | storage.type.class.ts 150 | 151 | 2 152 | 153 | name 154 | entity.name.type.class.ts 155 | 156 | 157 | end 158 | (?=\}) 159 | endCaptures 160 | 161 | 0 162 | 163 | name 164 | meta.brace.curly.ts 165 | 166 | 167 | name 168 | meta.class.ts 169 | patterns 170 | 171 | 172 | include 173 | #comment 174 | 175 | 176 | include 177 | #meta-class-body 178 | 179 | 180 | include 181 | #expression 182 | 183 | 184 | 185 | comment 186 | 187 | name 188 | comment.ts 189 | patterns 190 | 191 | 192 | include 193 | #comment-block-doc 194 | 195 | 196 | include 197 | #comment-block 198 | 199 | 200 | include 201 | #comment-block-html 202 | 203 | 204 | include 205 | #comment-line 206 | 207 | 208 | 209 | comment-block 210 | 211 | begin 212 | /\* 213 | captures 214 | 215 | 0 216 | 217 | name 218 | punctuation.definition.comment.ts 219 | 220 | 221 | end 222 | \*/ 223 | name 224 | comment.block.ts 225 | 226 | comment-block-doc 227 | 228 | begin 229 | /\*\*(?!/) 230 | captures 231 | 232 | 0 233 | 234 | name 235 | punctuation.definition.comment.ts 236 | 237 | 238 | end 239 | \*/ 240 | name 241 | comment.block.documentation.ts 242 | 243 | comment-block-html 244 | 245 | captures 246 | 247 | 0 248 | 249 | name 250 | punctuation.definition.comment.html.js 251 | 252 | 2 253 | 254 | name 255 | punctuation.definition.comment.html.js 256 | 257 | 258 | match 259 | (<!--|-->) 260 | name 261 | comment.block.html.js 262 | 263 | comment-line 264 | 265 | captures 266 | 267 | 1 268 | 269 | name 270 | punctuation.definition.comment.ts 271 | 272 | 273 | match 274 | (//).*$ 275 | ? 276 | name 277 | comment.line.double-slash.ts 278 | 279 | expression 280 | 281 | comment 282 | The main building block 283 | name 284 | meta.expression.ts 285 | patterns 286 | 287 | 288 | include 289 | #comment 290 | 291 | 292 | include 293 | #module-expression 294 | 295 | 296 | include 297 | #class-expression 298 | 299 | 300 | include 301 | #function 302 | 303 | 304 | include 305 | #block 306 | 307 | 308 | include 309 | #string 310 | 311 | 312 | include 313 | #regexp 314 | 315 | 316 | include 317 | #misc-higlighting 318 | 319 | 320 | 321 | function 322 | 323 | name 324 | meta.function.ts 325 | patterns 326 | 327 | 328 | include 329 | #meta-function-assignment 330 | 331 | 332 | include 333 | #meta-function-assignment-quoted 334 | 335 | 336 | include 337 | #meta-function 338 | 339 | 340 | 341 | meta-class-body 342 | 343 | begin 344 | \{ 345 | beginCaptures 346 | 347 | 0 348 | 349 | name 350 | meta.brace.curly.ts 351 | 352 | 353 | end 354 | (?=\}) 355 | endCaptures 356 | 357 | name 358 | meta.expression.body.class 359 | patterns 360 | 361 | 362 | include 363 | #comment 364 | 365 | 366 | include 367 | #meta-storage-modifier 368 | 369 | 370 | include 371 | #meta-class-member-attribute 372 | 373 | 374 | include 375 | #meta-class-member-method 376 | 377 | 378 | 379 | meta-class-member-attribute 380 | 381 | begin 382 | \b([a-zA-Z_$][\w$]*)\s*(?=(=|:)) 383 | beginCaptures 384 | 385 | 1 386 | 387 | name 388 | meta.toc-list.class.member.ts 389 | 390 | 391 | end 392 | (;) 393 | endCaptures 394 | 395 | 1 396 | 397 | name 398 | punctuation.terminator.statement.ts 399 | 400 | 401 | patterns 402 | 403 | 404 | include 405 | #meta-variable-type 406 | 407 | 408 | include 409 | #meta-variable-initializer 410 | 411 | 412 | 413 | meta-class-member-method 414 | 415 | begin 416 | \b(?:(get|set)\s+)?([a-zA-Z_$][\w$]*)\s*(?=\() 417 | beginCaptures 418 | 419 | 1 420 | 421 | name 422 | storage.type.property.ts 423 | 424 | 2 425 | 426 | name 427 | entity.name.function.ts 428 | 429 | 430 | end 431 | (\})|(;) 432 | endCaptures 433 | 434 | 1 435 | 436 | name 437 | meta.brace.curly.ts 438 | 439 | 2 440 | 441 | name 442 | punctuation.terminator.statement.ts 443 | 444 | 445 | name 446 | meta.class.member.ts 447 | patterns 448 | 449 | 450 | include 451 | #comment 452 | 453 | 454 | include 455 | #meta-function-parameters 456 | 457 | 458 | include 459 | #misc-higlighting 460 | 461 | 462 | include 463 | #meta-function-body 464 | 465 | 466 | 467 | meta-function 468 | 469 | begin 470 | \b(function)(?:\s+([a-zA-Z_$][\w$]*))?\s* 471 | beginCaptures 472 | 473 | 0 474 | 475 | name 476 | meta.function.ts 477 | 478 | 1 479 | 480 | name 481 | storage.type.function.ts 482 | 483 | 2 484 | 485 | name 486 | entity.name.function.ts 487 | 488 | 489 | end 490 | (\})|(;) 491 | endCaptures 492 | 493 | 0 494 | 495 | name 496 | meta.brace.curly.ts 497 | 498 | 499 | patterns 500 | 501 | 502 | include 503 | #comment 504 | 505 | 506 | include 507 | #meta-function-parameters 508 | 509 | 510 | include 511 | #meta-function-body 512 | 513 | 514 | include 515 | #misc-higlighting 516 | 517 | 518 | 519 | meta-function-assignment 520 | 521 | captures 522 | 523 | 1 524 | 525 | name 526 | entity.name.function.ts 527 | 528 | 2 529 | 530 | name 531 | keyword.operator.ts 532 | 533 | 534 | match 535 | \b([a-zA-Z_$][\w$]*)\s*(?:(=)|:)\s*(?=(\bfunction\b)) 536 | 537 | meta-function-assignment-quoted 538 | 539 | captures 540 | 541 | 1 542 | 543 | name 544 | string.quoted.single.ts 545 | 546 | 2 547 | 548 | name 549 | punctuation.definition.string.begin.ts 550 | 551 | 3 552 | 553 | name 554 | entity.name.function.ts 555 | 556 | 4 557 | 558 | name 559 | punctuation.definition.string.end.ts 560 | 561 | 5 562 | 563 | name 564 | string.quoted.double.ts 565 | 566 | 6 567 | 568 | name 569 | punctuation.definition.string.begin.ts 570 | 571 | 7 572 | 573 | name 574 | entity.name.function.ts 575 | 576 | 8 577 | 578 | name 579 | punctuation.definition.string.end.ts 580 | 581 | 582 | match 583 | (?:((')([^']*)('))|((")([^"]+)(")))\s*:\s*(?=\bfunction\b) 584 | 585 | meta-function-body 586 | 587 | begin 588 | \{ 589 | beginCaptures 590 | 591 | 0 592 | 593 | name 594 | meta.brace.curly.ts 595 | 596 | 597 | end 598 | (?=\}) 599 | endCaptures 600 | 601 | 0 602 | 603 | name 604 | meta.brace.curly.ts 605 | 606 | 607 | name 608 | meta.expression.body.function 609 | patterns 610 | 611 | 612 | include 613 | #expression 614 | 615 | 616 | 617 | meta-function-parameters 618 | 619 | begin 620 | \( 621 | beginCaptures 622 | 623 | 0 624 | 625 | name 626 | punctuation.definition.parameters.begin.ts 627 | 628 | 629 | end 630 | \) 631 | endCaptures 632 | 633 | 0 634 | 635 | name 636 | punctuation.definition.parameters.end.ts 637 | 638 | 639 | name 640 | meta.expression.body.class 641 | patterns 642 | 643 | 644 | include 645 | #comment 646 | 647 | 648 | include 649 | #meta-storage-modifier 650 | 651 | 652 | match 653 | [a-zA-Z_$][\w$]* 654 | name 655 | variable.parameter.function.ts 656 | 657 | 658 | include 659 | #meta-variable-type 660 | 661 | 662 | include 663 | #meta-variable-initializer 664 | 665 | 666 | 667 | meta-storage-modifier 668 | 669 | match 670 | \b(const|export|extends|final|implements|native|private|protected|public|static|synchronized|throws|transient|volatile)\b 671 | name 672 | storage.modifier.ts 673 | 674 | meta-variable-initializer 675 | 676 | begin 677 | (=) 678 | beginCaptures 679 | 680 | 1 681 | 682 | name 683 | keyword.operator.ts 684 | 685 | 686 | end 687 | (?=[,);=]) 688 | patterns 689 | 690 | 691 | include 692 | #expression 693 | 694 | 695 | 696 | meta-variable-type 697 | 698 | begin 699 | : 700 | end 701 | (?=[,);=]) 702 | patterns 703 | 704 | 705 | include 706 | #expression 707 | 708 | 709 | 710 | misc-higlighting 711 | 712 | comment 713 | This patterns are not affecting scope rules and are usefull for higlighting purposes only 714 | name 715 | misc.ts 716 | patterns 717 | 718 | 719 | captures 720 | 721 | 1 722 | 723 | name 724 | keyword.operator.new.ts 725 | 726 | 2 727 | 728 | name 729 | entity.name.type.instance.ts 730 | 731 | 732 | match 733 | (new)\s+(\w+(?:\.[\w$]*)*) 734 | name 735 | meta.class.instance.constructor 736 | 737 | 738 | captures 739 | 740 | 1 741 | 742 | name 743 | entity.name.type.object.ts.firebug 744 | 745 | 2 746 | 747 | name 748 | support.function.ts.firebug 749 | 750 | 751 | match 752 | \b(console)\.(warn|info|log|error|time|timeEnd|assert)\b 753 | name 754 | meta.object.ts.firebug 755 | 756 | 757 | match 758 | \b(console)\b 759 | name 760 | entity.name.type.object.ts.firebug 761 | 762 | 763 | match 764 | \b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b 765 | name 766 | constant.numeric.ts 767 | 768 | 769 | match 770 | \b(boolean|byte|char|class|double|enum|float|function|int|interface|long|number|short|string|var|void)\b 771 | name 772 | storage.type.ts 773 | 774 | 775 | include 776 | #meta-storage-modifier 777 | 778 | 779 | match 780 | \b(break|case|catch|continue|declare|default|do|else|finally|for|goto|if|import|package|return|switch|throw|try|while)\b 781 | name 782 | keyword.control.ts 783 | 784 | 785 | match 786 | \b(delete|in|instanceof|new|typeof|with)\b 787 | name 788 | keyword.operator.ts 789 | 790 | 791 | match 792 | \btrue\b 793 | name 794 | constant.language.boolean.true.ts 795 | 796 | 797 | match 798 | \bfalse\b 799 | name 800 | constant.language.boolean.false.ts 801 | 802 | 803 | match 804 | \bnull\b 805 | name 806 | constant.language.null.ts 807 | 808 | 809 | match 810 | \b(super|this)\b 811 | name 812 | support.constant.ts 813 | 814 | 815 | captures 816 | 817 | 1 818 | 819 | name 820 | meta.delimiter.method.period.ts 821 | 822 | 2 823 | 824 | name 825 | support.constant.ts 826 | 827 | 828 | match 829 | (\.)(prototype|__proto__)\b 830 | name 831 | meta.prototype.ts 832 | 833 | 834 | match 835 | \b(debugger)\b 836 | name 837 | keyword.other.ts 838 | 839 | 840 | match 841 | \b(Anchor|Applet|Area|Array|Boolean|Button|Checkbox|Date|document|event|FileUpload|Form|Frame|Function|Hidden|History|Image|JavaArray|JavaClass|JavaObject|JavaPackage|java|Layer|Link|Location|Math|MimeType|Number|navigator|netscape|Object|Option|Packages|Password|Plugin|Radio|RegExp|Reset|Select|String|Style|Submit|screen|sun|Text|Textarea|window|XMLHttpRequest)\b 842 | name 843 | support.class.ts 844 | 845 | 846 | match 847 | \b(require|module\.exports|module\.id|exports)\b 848 | name 849 | support.function.ts 850 | 851 | 852 | match 853 | \b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack))\b(?=\() 854 | name 855 | support.function.ts 856 | 857 | 858 | match 859 | \b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\() 860 | name 861 | support.function.dom.ts 862 | 863 | 864 | match 865 | (?<=\.)(s(ystemLanguage|cr(ipts|ollbars|een(X|Y|Top|Left))|t(yle(Sheets)?|atus(Text|bar)?)|ibling(Below|Above)|ource|uffixes|e(curity(Policy)?|l(ection|f)))|h(istory|ost(name)?|as(h|Focus))|y|X(MLDocument|SLDocument)|n(ext|ame(space(s|URI)|Prop))|M(IN_VALUE|AX_VALUE)|c(haracterSet|o(n(structor|trollers)|okieEnabled|lorDepth|mp(onents|lete))|urrent|puClass|l(i(p(boardData)?|entInformation)|osed|asses)|alle(e|r)|rypto)|t(o(olbar|p)|ext(Transform|Indent|Decoration|Align)|ags)|SQRT(1_2|2)|i(n(ner(Height|Width)|put)|ds|gnoreCase)|zIndex|o(scpu|n(readystatechange|Line)|uter(Height|Width)|p(sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(i(splay|alog(Height|Top|Width|Left|Arguments)|rectories)|e(scription|fault(Status|Ch(ecked|arset)|View)))|u(ser(Profile|Language|Agent)|n(iqueID|defined)|pdateInterval)|_content|p(ixelDepth|ort|ersonalbar|kcs11|l(ugins|atform)|a(thname|dding(Right|Bottom|Top|Left)|rent(Window|Layer)?|ge(X(Offset)?|Y(Offset)?))|r(o(to(col|type)|duct(Sub)?|mpter)|e(vious|fix)))|e(n(coding|abledPlugin)|x(ternal|pando)|mbeds)|v(isibility|endor(Sub)?|Linkcolor)|URLUnencoded|P(I|OSITIVE_INFINITY)|f(ilename|o(nt(Size|Family|Weight)|rmName)|rame(s|Element)|gColor)|E|whiteSpace|l(i(stStyleType|n(eHeight|kColor))|o(ca(tion(bar)?|lName)|wsrc)|e(ngth|ft(Context)?)|a(st(M(odified|atch)|Index|Paren)|yer(s|X)|nguage))|a(pp(MinorVersion|Name|Co(deName|re)|Version)|vail(Height|Top|Width|Left)|ll|r(ity|guments)|Linkcolor|bove)|r(ight(Context)?|e(sponse(XML|Text)|adyState))|global|x|m(imeTypes|ultiline|enubar|argin(Right|Bottom|Top|Left))|L(N(10|2)|OG(10E|2E))|b(o(ttom|rder(Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(Color|Image)))\b 866 | name 867 | support.constant.ts 868 | 869 | 870 | match 871 | (?<=\.)(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\b 872 | name 873 | support.constant.dom.ts 874 | 875 | 876 | match 877 | \b(ELEMENT_NODE|ATTRIBUTE_NODE|TEXT_NODE|CDATA_SECTION_NODE|ENTITY_REFERENCE_NODE|ENTITY_NODE|PROCESSING_INSTRUCTION_NODE|COMMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE|DOCUMENT_FRAGMENT_NODE|NOTATION_NODE|INDEX_SIZE_ERR|DOMSTRING_SIZE_ERR|HIERARCHY_REQUEST_ERR|WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR)\b 878 | name 879 | support.constant.dom.ts 880 | 881 | 882 | match 883 | \bon(R(ow(s(inserted|delete)|e(nter|xit))|e(s(ize(start|end)?|et)|adystatechange))|Mouse(o(ut|ver)|down|up|move)|B(efore(cut|deactivate|u(nload|pdate)|p(aste|rint)|editfocus|activate)|lur)|S(croll|top|ubmit|elect(start|ionchange)?)|H(over|elp)|C(hange|ont(extmenu|rolselect)|ut|ellchange|l(ick|ose))|D(eactivate|ata(setc(hanged|omplete)|available)|r(op|ag(start|over|drop|en(ter|d)|leave)?)|blclick)|Unload|P(aste|ropertychange)|Error(update)?|Key(down|up|press)|Focus|Load|A(ctivate|fter(update|print)|bort))\b 884 | name 885 | support.function.event-handler.ts 886 | 887 | 888 | match 889 | !|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|void)\b 890 | name 891 | keyword.operator.ts 892 | 893 | 894 | match 895 | \b(Infinity|NaN|undefined)\b 896 | name 897 | constant.language.ts 898 | 899 | 900 | match 901 | \; 902 | name 903 | punctuation.terminator.statement.ts 904 | 905 | 906 | match 907 | ,[ |\t]* 908 | name 909 | meta.delimiter.object.comma.ts 910 | 911 | 912 | match 913 | \. 914 | name 915 | meta.delimiter.method.period.ts 916 | 917 | 918 | match 919 | \[|\] 920 | name 921 | meta.brace.square.ts 922 | 923 | 924 | 925 | module-expression 926 | 927 | begin 928 | \b(module)\b(?:\s+([a-zA-Z_$][\w$]*))? 929 | beginCaptures 930 | 931 | 1 932 | 933 | name 934 | storage.type.module.ts 935 | 936 | 2 937 | 938 | name 939 | entity.name.type.module.ts 940 | 941 | 942 | end 943 | (?=\}) 944 | endCaptures 945 | 946 | 0 947 | 948 | name 949 | meta.brace.curly.ts 950 | 951 | 952 | name 953 | meta.module.ts 954 | patterns 955 | 956 | 957 | include 958 | #expression 959 | 960 | 961 | 962 | regexp 963 | 964 | begin 965 | (?<=[=(:]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?]) 966 | beginCaptures 967 | 968 | 1 969 | 970 | name 971 | punctuation.definition.string.begin.ts 972 | 973 | 974 | end 975 | (/)[igm]* 976 | endCaptures 977 | 978 | 1 979 | 980 | name 981 | punctuation.definition.string.end.ts 982 | 983 | 984 | name 985 | string.regexp.ts 986 | patterns 987 | 988 | 989 | match 990 | \\. 991 | name 992 | constant.character.escape.ts 993 | 994 | 995 | 996 | shebang 997 | 998 | comment 999 | node.js shebang 1000 | match 1001 | ^#![\S]+ node 1002 | name 1003 | comment.line.ts 1004 | 1005 | string 1006 | 1007 | name 1008 | string.ts 1009 | patterns 1010 | 1011 | 1012 | include 1013 | #string-quoted-single 1014 | 1015 | 1016 | include 1017 | #string-quoted-double 1018 | 1019 | 1020 | 1021 | string-quoted-double 1022 | 1023 | begin 1024 | " 1025 | beginCaptures 1026 | 1027 | 0 1028 | 1029 | name 1030 | punctuation.definition.string.begin.ts 1031 | 1032 | 1033 | end 1034 | " 1035 | endCaptures 1036 | 1037 | 0 1038 | 1039 | name 1040 | punctuation.definition.string.end.ts 1041 | 1042 | 1043 | name 1044 | string.quoted.double.ts 1045 | patterns 1046 | 1047 | 1048 | match 1049 | \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.) 1050 | name 1051 | constant.character.escape.ts 1052 | 1053 | 1054 | 1055 | string-quoted-single 1056 | 1057 | begin 1058 | ' 1059 | beginCaptures 1060 | 1061 | 0 1062 | 1063 | name 1064 | punctuation.definition.string.begin.ts 1065 | 1066 | 1067 | end 1068 | ' 1069 | endCaptures 1070 | 1071 | 0 1072 | 1073 | name 1074 | punctuation.definition.string.end.ts 1075 | 1076 | 1077 | name 1078 | string.quoted.single.ts 1079 | patterns 1080 | 1081 | 1082 | match 1083 | \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.) 1084 | name 1085 | constant.character.escape.ts 1086 | 1087 | 1088 | 1089 | 1090 | scopeName 1091 | source.ts 1092 | uuid 1093 | 6bca3b85-82b7-4828-9573-8b91192dffe6 1094 | 1095 | 1096 | -------------------------------------------------------------------------------- /changelogs/0.9.md: -------------------------------------------------------------------------------- 1 | # Better TypeScript changelog 2 | ## Version 0.9 3 | 4 | Lint functionality is removed for plugin. If you still need it, please, look at [https://github.com/lavrton/SublimeLinter-contrib-tslint](SublimeLinter-contrib-tslint) 5 | 6 | Repair watch mode. -------------------------------------------------------------------------------- /changelogs/1.0.0.md: -------------------------------------------------------------------------------- 1 | # Better TypeScript changelog 2 | ## Version 0.9.1 3 | 4 | The plugin is now deprecated. You can use official typescript plugin (https://packagecontrol.io/packages/TypeScript). -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "README.md", 3 | "0.9": "changelogs/0.9.md", 4 | "1.0.0": "changelogs/1.0.0.md" 5 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema_version": "1.2", 3 | "renamed_packages": { "sublime-better-typescript": "Better TypeScript" }, 4 | "packages": [ 5 | { 6 | "name": "Better TypeScript", 7 | "description": "Syntax highlighting and checking, commands, shortcuts, snippets, watched compilation and more.", 8 | "author": "lavrton", 9 | "homepage": "https://github.com/lavrton/sublime-better-typescript", 10 | "last_modified": "2013-05-26 05:04:41", 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /sourcemap/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | sourcemap 3 | ~~~~~~~~~ 4 | 5 | :copyright: (c) 2013 by Matt Robenolt 6 | :license: BSD, see LICENSE for more details. 7 | """ 8 | from .exceptions import SourceMapDecodeError #NOQA 9 | from .decoder import SourceMapDecoder 10 | 11 | __version__ = '0.1.7' 12 | 13 | 14 | def load(fp, cls=None): 15 | "Parse a sourcemap from a file-like object" 16 | return loads(fp.read(), cls) 17 | 18 | 19 | def loads(source, cls=None): 20 | "Parse a sourcemap from a string" 21 | cls = cls or SourceMapDecoder 22 | return cls().decode(source) 23 | 24 | 25 | def discover(source): 26 | "Given a JavaScript file, find the sourceMappingURL line" 27 | source = source.splitlines() 28 | # Source maps are only going to exist at either the top or bottom of the document. 29 | # Technically, there isn't anything indicating *where* it should exist, so we 30 | # are generous and assume it's somewhere either in the first or last 5 lines. 31 | # If it's somewhere else in the document, you're probably doing it wrong. 32 | if len(source) > 10: 33 | possibilities = source[:5] + source[-5:] 34 | else: 35 | possibilities = source 36 | 37 | for line in set(possibilities): 38 | pragma = line[:21] 39 | if pragma == '//# sourceMappingURL=' or pragma == '//@ sourceMappingURL=': 40 | # We want everything AFTER the pragma, which is 21 chars long 41 | return line[21:].rstrip() 42 | # XXX: Return None or raise an exception? 43 | return None 44 | -------------------------------------------------------------------------------- /sourcemap/decoder.py: -------------------------------------------------------------------------------- 1 | """ 2 | sourcemap.decoder 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Includes source from: 6 | https://github.com/martine/python-sourcemap 7 | Original source under Apache license, see: 8 | https://github.com/martine/python-sourcemap/blob/master/COPYING 9 | 10 | :copyright: (c) 2013 by Matt Robenolt 11 | :license: BSD, see LICENSE for more details. 12 | """ 13 | import os 14 | import sys 15 | from functools import partial 16 | from .exceptions import SourceMapDecodeError 17 | from .objects import Token, SourceMapIndex 18 | try: 19 | import simplejson as json 20 | except ImportError: 21 | import json #NOQA 22 | 23 | __all__ = ('SourceMapDecoder',) 24 | 25 | # True if we are running on Python 3. 26 | PY3 = sys.version_info[0] == 3 27 | text_type = str if PY3 else unicode 28 | 29 | 30 | class SourceMapDecoder(object): 31 | def parse_vlq(self, segment): 32 | """ 33 | Parse a string of VLQ-encoded data. 34 | 35 | Returns: 36 | a list of integers. 37 | """ 38 | 39 | values = [] 40 | 41 | cur, shift = 0, 0 42 | for c in segment: 43 | val = B64[ord(c)] 44 | # Each character is 6 bits: 45 | # 5 of value and the high bit is the continuation. 46 | val, cont = val & 0b11111, val >> 5 47 | cur += val << shift 48 | shift += 5 49 | 50 | if not cont: 51 | # The low bit of the unpacked value is the sign. 52 | cur, sign = cur >> 1, cur & 1 53 | if sign: 54 | cur = -cur 55 | values.append(cur) 56 | cur, shift = 0, 0 57 | 58 | if cur or shift: 59 | raise SourceMapDecodeError('leftover cur/shift in vlq decode') 60 | 61 | return values 62 | 63 | def decode(self, source): 64 | """Decode a source map object into a SourceMapIndex. 65 | 66 | The index is keyed on (dst_line, dst_column) for lookups, 67 | and a per row index is kept to help calculate which Token to retrieve. 68 | 69 | For example: 70 | A minified source file has two rows and two tokens per row. 71 | 72 | # All parsed tokens 73 | tokens = [ 74 | Token(dst_row=0, dst_col=0), 75 | Token(dst_row=0, dst_col=5), 76 | Token(dst_row=1, dst_col=0), 77 | Token(dst_row=1, dst_col=12), 78 | ] 79 | 80 | Two dimentional array of columns -> row 81 | rows = [ 82 | [0, 5], 83 | [0, 12], 84 | ] 85 | 86 | Token lookup, based on location 87 | index = { 88 | (0, 0): tokens[0], 89 | (0, 5): tokens[1], 90 | (1, 0): tokens[2], 91 | (1, 12): tokens[3], 92 | } 93 | 94 | To find the token at (1, 20): 95 | - Check if there's a direct hit on the index (1, 20) => False 96 | - Pull rows[1] => [0, 12] 97 | - bisect_right to find the closest match: 98 | bisect_right([0, 12], 20) => 2 99 | - Fetch the column number before, since we want the column 100 | lte to the bisect_right: 2-1 => row[2-1] => 12 101 | - At this point, we know the token location, (1, 12) 102 | - Pull (1, 12) from index => tokens[3] 103 | """ 104 | # According to spec (https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.h7yy76c5il9v) 105 | # A SouceMap may be prepended with ")]}'" to cause a Javascript error. 106 | # If the file starts with that string, ignore the entire first line. 107 | if source[:3] == ')]}': 108 | source = source.split('\n', 1)[1] 109 | 110 | smap = json.loads(source) 111 | sources = smap['sources'] 112 | sourceRoot = smap.get('sourceRoot') 113 | names = list(map(text_type, smap['names'])) 114 | mappings = smap['mappings'] 115 | lines = mappings.split(';') 116 | 117 | # if sourceRoot is not None: 118 | # sources = map(partial(os.path.join, sourceRoot), sources) 119 | 120 | # List of all tokens 121 | tokens = [] 122 | 123 | # line_index is used to identify the closest column when looking up a token 124 | line_index = [] 125 | 126 | # Main index of all tokens 127 | # The index is keyed on (line, column) 128 | index = {} 129 | 130 | dst_col, src_id, src_line, src_col, name_id = 0, 0, 0, 0, 0 131 | for dst_line, line in enumerate(lines): 132 | # Create list for columns in index 133 | line_index.append([]) 134 | 135 | segments = line.split(',') 136 | dst_col = 0 137 | for segment in segments: 138 | if not segment: 139 | continue 140 | parse = self.parse_vlq(segment) 141 | dst_col += parse[0] 142 | 143 | src = None 144 | name = None 145 | if len(parse) > 1: 146 | try: 147 | src_id += parse[1] 148 | src = sources[src_id] 149 | src_line += parse[2] 150 | src_col += parse[3] 151 | 152 | if len(parse) > 4: 153 | name_id += parse[4] 154 | name = names[name_id] 155 | except IndexError: 156 | raise SourceMapDecodeError 157 | 158 | # lol for now 159 | try: 160 | assert dst_line >= 0 161 | assert dst_col >= 0 162 | assert src_line >= 0 163 | assert src_col >= 0 164 | except AssertionError: 165 | raise SourceMapDecodeError 166 | 167 | token = Token(dst_line, dst_col, src, src_line, src_col, name) 168 | tokens.append(token) 169 | 170 | # Insert into main index 171 | index[(dst_line, dst_col)] = token 172 | 173 | # Insert into specific line index 174 | line_index[dst_line].append(dst_col) 175 | 176 | return SourceMapIndex(smap, tokens, line_index, index, sources) 177 | 178 | 179 | # Mapping of base64 letter -> integer value. 180 | # This weird list is being allocated for faster lookups 181 | B64 = [-1] * 123 182 | for i, c in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): 183 | B64[ord(c)] = i 184 | -------------------------------------------------------------------------------- /sourcemap/exceptions.py: -------------------------------------------------------------------------------- 1 | """ 2 | sourcemap.exceptions 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | :copyright: (c) 2013 by Matt Robenolt 6 | :license: BSD, see LICENSE for more details. 7 | """ 8 | class SourceMapDecodeError(ValueError): 9 | "lol sourcemap error" 10 | pass 11 | -------------------------------------------------------------------------------- /sourcemap/objects.py: -------------------------------------------------------------------------------- 1 | """ 2 | sourcemap.objects 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | :copyright: (c) 2013 by Matt Robenolt 6 | :license: BSD, see LICENSE for more details. 7 | """ 8 | from bisect import bisect_right 9 | 10 | 11 | class Token(object): 12 | """A Token represents one JavaScript symbol. 13 | 14 | Each token holds a reference to: 15 | Original line number: dst_line 16 | Original column number: dst_col 17 | Source file name: src 18 | Source line number: src_line 19 | Source column number: src_col 20 | Name of the token: name 21 | """ 22 | def __init__(self, dst_line=0, dst_col=0, src='', src_line=0, src_col=0, name=None): 23 | self.dst_line = dst_line 24 | self.dst_col = dst_col 25 | self.src = src 26 | self.src_line = src_line 27 | self.src_col = src_col 28 | self.name = name 29 | 30 | # def __str__(self): 31 | # return str(self.name) 32 | 33 | # def __unicode__(self): 34 | # return unicode(self.name) 35 | 36 | def __eq__(self, other): 37 | keys = ('dst_line', 'dst_col', 'src', 'src_line', 'src_col', 'name') 38 | for key in keys: 39 | if getattr(self, key) != getattr(other, key): 40 | return False 41 | return True 42 | 43 | # def __repr__(self): 44 | # args = self.src, self.dst_line, self.dst_col, self.src_line, self.src_col, self.name 45 | # return '' % args 46 | 47 | 48 | class SourceMapIndex(object): 49 | """The indexed sourcemap containing all the Tokens 50 | and precomputed indexes for searching.""" 51 | 52 | def __init__(self, raw, tokens, line_index, index, sources=None): 53 | self.raw = raw 54 | self.tokens = tokens 55 | self.line_index = line_index 56 | self.index = index 57 | self.sources = sources or [] 58 | 59 | def lookup(self, line, column): 60 | try: 61 | # Let's hope for a direct match first 62 | return self.index[(line, column)] 63 | except KeyError: 64 | pass 65 | 66 | # Figure out which line to search through 67 | line_index = self.line_index[line] 68 | # Find the closest column token 69 | line_index 70 | i = bisect_right(line_index, column) 71 | if not i: 72 | # You're gonna have a bad time 73 | i = len(line_index)-2 74 | # raise IndexError 75 | 76 | # We actually want the one less than current 77 | column = line_index[i - 1] 78 | # Return from the main index, based on the (line, column) tuple 79 | return self.index[(line, column)] 80 | 81 | def getpos(self,line,column): 82 | for l in range(len(self.line_index)): 83 | for c in self.line_index[l]: 84 | if self.lookup(l,c).src_line ==line: 85 | return l,c 86 | 87 | # for j in range(column): 88 | # if self.lookup 89 | # if self.lookup() 90 | 91 | def __getitem__(self, item): 92 | return self.tokens[item] 93 | 94 | def __iter__(self): 95 | return iter(self.tokens) 96 | 97 | def __len__(self): 98 | return len(self.tokens) 99 | 100 | def __repr__(self): 101 | return '' % ', '.join(map(str, self.sources)) 102 | --------------------------------------------------------------------------------