scope.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /***********************************************************************
  2. A JavaScript tokenizer / parser / beautifier / compressor.
  3. https://github.com/mishoo/UglifyJS2
  4. -------------------------------- (C) ---------------------------------
  5. Author: Mihai Bazon
  6. <mihai.bazon@gmail.com>
  7. http://mihai.bazon.net/blog
  8. Distributed under the BSD license:
  9. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions
  12. are met:
  13. * Redistributions of source code must retain the above
  14. copyright notice, this list of conditions and the following
  15. disclaimer.
  16. * Redistributions in binary form must reproduce the above
  17. copyright notice, this list of conditions and the following
  18. disclaimer in the documentation and/or other materials
  19. provided with the distribution.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
  21. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  29. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. SUCH DAMAGE.
  32. ***********************************************************************/
  33. "use strict";
  34. function SymbolDef(scope, index, orig) {
  35. this.name = orig.name;
  36. this.orig = [ orig ];
  37. this.scope = scope;
  38. this.references = [];
  39. this.global = false;
  40. this.mangled_name = null;
  41. this.undeclared = false;
  42. this.index = index;
  43. this.id = SymbolDef.next_id++;
  44. };
  45. SymbolDef.next_id = 1;
  46. SymbolDef.prototype = {
  47. unmangleable: function(options) {
  48. if (!options) options = {};
  49. return (this.global && !options.toplevel)
  50. || this.undeclared
  51. || (!options.eval && (this.scope.uses_eval || this.scope.uses_with))
  52. || (options.keep_fnames
  53. && (this.orig[0] instanceof AST_SymbolLambda
  54. || this.orig[0] instanceof AST_SymbolDefun));
  55. },
  56. mangle: function(options) {
  57. var cache = options.cache && options.cache.props;
  58. if (this.global && cache && cache.has(this.name)) {
  59. this.mangled_name = cache.get(this.name);
  60. }
  61. else if (!this.mangled_name && !this.unmangleable(options)) {
  62. var s = this.scope;
  63. var sym = this.orig[0];
  64. if (!options.screw_ie8 && sym instanceof AST_SymbolLambda)
  65. s = s.parent_scope;
  66. var def;
  67. if (this.defun && (def = this.defun.variables.get(this.name))) {
  68. this.mangled_name = def.mangled_name || def.name;
  69. } else
  70. this.mangled_name = s.next_mangled(options, this);
  71. if (this.global && cache) {
  72. cache.set(this.name, this.mangled_name);
  73. }
  74. }
  75. }
  76. };
  77. AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
  78. options = defaults(options, {
  79. cache: null,
  80. screw_ie8: true,
  81. });
  82. // pass 1: setup scope chaining and handle definitions
  83. var self = this;
  84. var scope = self.parent_scope = null;
  85. var labels = new Dictionary();
  86. var defun = null;
  87. var tw = new TreeWalker(function(node, descend){
  88. if (node instanceof AST_Catch) {
  89. var save_scope = scope;
  90. scope = new AST_Scope(node);
  91. scope.init_scope_vars(save_scope);
  92. descend();
  93. scope = save_scope;
  94. return true;
  95. }
  96. if (node instanceof AST_Scope) {
  97. node.init_scope_vars(scope);
  98. var save_scope = scope;
  99. var save_defun = defun;
  100. var save_labels = labels;
  101. defun = scope = node;
  102. labels = new Dictionary();
  103. descend();
  104. scope = save_scope;
  105. defun = save_defun;
  106. labels = save_labels;
  107. return true; // don't descend again in TreeWalker
  108. }
  109. if (node instanceof AST_LabeledStatement) {
  110. var l = node.label;
  111. if (labels.has(l.name)) {
  112. throw new Error(string_template("Label {name} defined twice", l));
  113. }
  114. labels.set(l.name, l);
  115. descend();
  116. labels.del(l.name);
  117. return true; // no descend again
  118. }
  119. if (node instanceof AST_With) {
  120. for (var s = scope; s; s = s.parent_scope)
  121. s.uses_with = true;
  122. return;
  123. }
  124. if (node instanceof AST_Symbol) {
  125. node.scope = scope;
  126. }
  127. if (node instanceof AST_Label) {
  128. node.thedef = node;
  129. node.references = [];
  130. }
  131. if (node instanceof AST_SymbolLambda) {
  132. defun.def_function(node);
  133. }
  134. else if (node instanceof AST_SymbolDefun) {
  135. // Careful here, the scope where this should be defined is
  136. // the parent scope. The reason is that we enter a new
  137. // scope when we encounter the AST_Defun node (which is
  138. // instanceof AST_Scope) but we get to the symbol a bit
  139. // later.
  140. (node.scope = defun.parent_scope).def_function(node);
  141. }
  142. else if (node instanceof AST_SymbolVar
  143. || node instanceof AST_SymbolConst) {
  144. defun.def_variable(node);
  145. if (defun !== scope) {
  146. node.mark_enclosed(options);
  147. var def = scope.find_variable(node);
  148. if (node.thedef !== def) {
  149. node.thedef = def;
  150. node.reference(options);
  151. }
  152. }
  153. }
  154. else if (node instanceof AST_SymbolCatch) {
  155. scope.def_variable(node).defun = defun;
  156. }
  157. else if (node instanceof AST_LabelRef) {
  158. var sym = labels.get(node.name);
  159. if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
  160. name: node.name,
  161. line: node.start.line,
  162. col: node.start.col
  163. }));
  164. node.thedef = sym;
  165. }
  166. });
  167. self.walk(tw);
  168. // pass 2: find back references and eval
  169. var func = null;
  170. var globals = self.globals = new Dictionary();
  171. var tw = new TreeWalker(function(node, descend){
  172. if (node instanceof AST_Lambda) {
  173. var prev_func = func;
  174. func = node;
  175. descend();
  176. func = prev_func;
  177. return true;
  178. }
  179. if (node instanceof AST_LoopControl && node.label) {
  180. node.label.thedef.references.push(node);
  181. return true;
  182. }
  183. if (node instanceof AST_SymbolRef) {
  184. var name = node.name;
  185. if (name == "eval" && tw.parent() instanceof AST_Call) {
  186. for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
  187. s.uses_eval = true;
  188. }
  189. }
  190. var sym = node.scope.find_variable(name);
  191. if (node.scope instanceof AST_Lambda && name == "arguments") {
  192. node.scope.uses_arguments = true;
  193. }
  194. if (!sym) {
  195. sym = self.def_global(node);
  196. }
  197. node.thedef = sym;
  198. node.reference(options);
  199. return true;
  200. }
  201. });
  202. self.walk(tw);
  203. // pass 3: fix up any scoping issue with IE8
  204. if (!options.screw_ie8) {
  205. self.walk(new TreeWalker(function(node, descend) {
  206. if (node instanceof AST_SymbolCatch) {
  207. var name = node.name;
  208. var refs = node.thedef.references;
  209. var scope = node.thedef.defun;
  210. var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
  211. refs.forEach(function(ref) {
  212. ref.thedef = def;
  213. ref.reference(options);
  214. });
  215. node.thedef = def;
  216. return true;
  217. }
  218. }));
  219. }
  220. if (options.cache) {
  221. this.cname = options.cache.cname;
  222. }
  223. });
  224. AST_Toplevel.DEFMETHOD("def_global", function(node){
  225. var globals = this.globals, name = node.name;
  226. if (globals.has(name)) {
  227. return globals.get(name);
  228. } else {
  229. var g = new SymbolDef(this, globals.size(), node);
  230. g.undeclared = true;
  231. g.global = true;
  232. globals.set(name, g);
  233. return g;
  234. }
  235. });
  236. AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
  237. this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
  238. this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
  239. this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
  240. this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
  241. this.parent_scope = parent_scope; // the parent scope
  242. this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes
  243. this.cname = -1; // the current index for mangling functions/variables
  244. });
  245. AST_Lambda.DEFMETHOD("init_scope_vars", function(){
  246. AST_Scope.prototype.init_scope_vars.apply(this, arguments);
  247. this.uses_arguments = false;
  248. this.def_variable(new AST_SymbolVar({
  249. name: "arguments",
  250. start: this.start,
  251. end: this.end
  252. }));
  253. });
  254. AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
  255. var def = this.definition();
  256. var s = this.scope;
  257. while (s) {
  258. push_uniq(s.enclosed, def);
  259. if (options.keep_fnames) {
  260. s.functions.each(function(d) {
  261. push_uniq(def.scope.enclosed, d);
  262. });
  263. }
  264. if (s === def.scope) break;
  265. s = s.parent_scope;
  266. }
  267. });
  268. AST_Symbol.DEFMETHOD("reference", function(options) {
  269. this.definition().references.push(this);
  270. this.mark_enclosed(options);
  271. });
  272. AST_Scope.DEFMETHOD("find_variable", function(name){
  273. if (name instanceof AST_Symbol) name = name.name;
  274. return this.variables.get(name)
  275. || (this.parent_scope && this.parent_scope.find_variable(name));
  276. });
  277. AST_Scope.DEFMETHOD("def_function", function(symbol){
  278. this.functions.set(symbol.name, this.def_variable(symbol));
  279. });
  280. AST_Scope.DEFMETHOD("def_variable", function(symbol){
  281. var def;
  282. if (!this.variables.has(symbol.name)) {
  283. def = new SymbolDef(this, this.variables.size(), symbol);
  284. this.variables.set(symbol.name, def);
  285. def.global = !this.parent_scope;
  286. } else {
  287. def = this.variables.get(symbol.name);
  288. def.orig.push(symbol);
  289. }
  290. return symbol.thedef = def;
  291. });
  292. AST_Scope.DEFMETHOD("next_mangled", function(options){
  293. var ext = this.enclosed;
  294. out: while (true) {
  295. var m = base54(++this.cname);
  296. if (!is_identifier(m)) continue; // skip over "do"
  297. // https://github.com/mishoo/UglifyJS2/issues/242 -- do not
  298. // shadow a name excepted from mangling.
  299. if (options.except.indexOf(m) >= 0) continue;
  300. // we must ensure that the mangled name does not shadow a name
  301. // from some parent scope that is referenced in this or in
  302. // inner scopes.
  303. for (var i = ext.length; --i >= 0;) {
  304. var sym = ext[i];
  305. var name = sym.mangled_name || (sym.unmangleable(options) && sym.name);
  306. if (m == name) continue out;
  307. }
  308. return m;
  309. }
  310. });
  311. AST_Function.DEFMETHOD("next_mangled", function(options, def){
  312. // #179, #326
  313. // in Safari strict mode, something like (function x(x){...}) is a syntax error;
  314. // a function expression's argument cannot shadow the function expression's name
  315. var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
  316. // the function's mangled_name is null when keep_fnames is true
  317. var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
  318. while (true) {
  319. var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
  320. if (!tricky_name || tricky_name != name)
  321. return name;
  322. }
  323. });
  324. AST_Symbol.DEFMETHOD("unmangleable", function(options){
  325. return this.definition().unmangleable(options);
  326. });
  327. // labels are always mangleable
  328. AST_Label.DEFMETHOD("unmangleable", function(){
  329. return false;
  330. });
  331. AST_Symbol.DEFMETHOD("unreferenced", function(){
  332. return this.definition().references.length == 0
  333. && !(this.scope.uses_eval || this.scope.uses_with);
  334. });
  335. AST_Symbol.DEFMETHOD("undeclared", function(){
  336. return this.definition().undeclared;
  337. });
  338. AST_LabelRef.DEFMETHOD("undeclared", function(){
  339. return false;
  340. });
  341. AST_Label.DEFMETHOD("undeclared", function(){
  342. return false;
  343. });
  344. AST_Symbol.DEFMETHOD("definition", function(){
  345. return this.thedef;
  346. });
  347. AST_Symbol.DEFMETHOD("global", function(){
  348. return this.definition().global;
  349. });
  350. AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
  351. return defaults(options, {
  352. eval : false,
  353. except : [],
  354. keep_fnames : false,
  355. screw_ie8 : true,
  356. sort : false, // Ignored. Flag retained for backwards compatibility.
  357. toplevel : false,
  358. });
  359. });
  360. AST_Toplevel.DEFMETHOD("mangle_names", function(options){
  361. options = this._default_mangler_options(options);
  362. // Never mangle arguments
  363. options.except.push('arguments');
  364. // We only need to mangle declaration nodes. Special logic wired
  365. // into the code generator will display the mangled name if it's
  366. // present (and for AST_SymbolRef-s it'll use the mangled name of
  367. // the AST_SymbolDeclaration that it points to).
  368. var lname = -1;
  369. var to_mangle = [];
  370. if (options.cache) {
  371. this.globals.each(function(symbol){
  372. if (options.except.indexOf(symbol.name) < 0) {
  373. to_mangle.push(symbol);
  374. }
  375. });
  376. }
  377. var tw = new TreeWalker(function(node, descend){
  378. if (node instanceof AST_LabeledStatement) {
  379. // lname is incremented when we get to the AST_Label
  380. var save_nesting = lname;
  381. descend();
  382. lname = save_nesting;
  383. return true; // don't descend again in TreeWalker
  384. }
  385. if (node instanceof AST_Scope) {
  386. var p = tw.parent(), a = [];
  387. node.variables.each(function(symbol){
  388. if (options.except.indexOf(symbol.name) < 0) {
  389. a.push(symbol);
  390. }
  391. });
  392. to_mangle.push.apply(to_mangle, a);
  393. return;
  394. }
  395. if (node instanceof AST_Label) {
  396. var name;
  397. do name = base54(++lname); while (!is_identifier(name));
  398. node.mangled_name = name;
  399. return true;
  400. }
  401. if (options.screw_ie8 && node instanceof AST_SymbolCatch) {
  402. to_mangle.push(node.definition());
  403. return;
  404. }
  405. });
  406. this.walk(tw);
  407. to_mangle.forEach(function(def){ def.mangle(options) });
  408. if (options.cache) {
  409. options.cache.cname = this.cname;
  410. }
  411. });
  412. AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
  413. options = this._default_mangler_options(options);
  414. var tw = new TreeWalker(function(node){
  415. if (node instanceof AST_Constant)
  416. base54.consider(node.print_to_string());
  417. else if (node instanceof AST_Return)
  418. base54.consider("return");
  419. else if (node instanceof AST_Throw)
  420. base54.consider("throw");
  421. else if (node instanceof AST_Continue)
  422. base54.consider("continue");
  423. else if (node instanceof AST_Break)
  424. base54.consider("break");
  425. else if (node instanceof AST_Debugger)
  426. base54.consider("debugger");
  427. else if (node instanceof AST_Directive)
  428. base54.consider(node.value);
  429. else if (node instanceof AST_While)
  430. base54.consider("while");
  431. else if (node instanceof AST_Do)
  432. base54.consider("do while");
  433. else if (node instanceof AST_If) {
  434. base54.consider("if");
  435. if (node.alternative) base54.consider("else");
  436. }
  437. else if (node instanceof AST_Var)
  438. base54.consider("var");
  439. else if (node instanceof AST_Const)
  440. base54.consider("const");
  441. else if (node instanceof AST_Lambda)
  442. base54.consider("function");
  443. else if (node instanceof AST_For)
  444. base54.consider("for");
  445. else if (node instanceof AST_ForIn)
  446. base54.consider("for in");
  447. else if (node instanceof AST_Switch)
  448. base54.consider("switch");
  449. else if (node instanceof AST_Case)
  450. base54.consider("case");
  451. else if (node instanceof AST_Default)
  452. base54.consider("default");
  453. else if (node instanceof AST_With)
  454. base54.consider("with");
  455. else if (node instanceof AST_ObjectSetter)
  456. base54.consider("set" + node.key);
  457. else if (node instanceof AST_ObjectGetter)
  458. base54.consider("get" + node.key);
  459. else if (node instanceof AST_ObjectKeyVal)
  460. base54.consider(node.key);
  461. else if (node instanceof AST_New)
  462. base54.consider("new");
  463. else if (node instanceof AST_This)
  464. base54.consider("this");
  465. else if (node instanceof AST_Try)
  466. base54.consider("try");
  467. else if (node instanceof AST_Catch)
  468. base54.consider("catch");
  469. else if (node instanceof AST_Finally)
  470. base54.consider("finally");
  471. else if (node instanceof AST_Symbol && node.unmangleable(options))
  472. base54.consider(node.name);
  473. else if (node instanceof AST_Unary || node instanceof AST_Binary)
  474. base54.consider(node.operator);
  475. else if (node instanceof AST_Dot)
  476. base54.consider(node.property);
  477. });
  478. this.walk(tw);
  479. base54.sort();
  480. });
  481. var base54 = (function() {
  482. var string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
  483. var chars, frequency;
  484. function reset() {
  485. frequency = Object.create(null);
  486. chars = string.split("").map(function(ch){ return ch.charCodeAt(0) });
  487. chars.forEach(function(ch){ frequency[ch] = 0 });
  488. }
  489. base54.consider = function(str){
  490. for (var i = str.length; --i >= 0;) {
  491. var code = str.charCodeAt(i);
  492. if (code in frequency) ++frequency[code];
  493. }
  494. };
  495. base54.sort = function() {
  496. chars = mergeSort(chars, function(a, b){
  497. if (is_digit(a) && !is_digit(b)) return 1;
  498. if (is_digit(b) && !is_digit(a)) return -1;
  499. return frequency[b] - frequency[a];
  500. });
  501. };
  502. base54.reset = reset;
  503. reset();
  504. base54.get = function(){ return chars };
  505. base54.freq = function(){ return frequency };
  506. function base54(num) {
  507. var ret = "", base = 54;
  508. num++;
  509. do {
  510. num--;
  511. ret += String.fromCharCode(chars[num % base]);
  512. num = Math.floor(num / base);
  513. base = 64;
  514. } while (num > 0);
  515. return ret;
  516. };
  517. return base54;
  518. })();
  519. AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
  520. options = defaults(options, {
  521. assign_to_global : true,
  522. eval : true,
  523. func_arguments : true,
  524. nested_defuns : true,
  525. undeclared : false, // this makes a lot of noise
  526. unreferenced : true,
  527. });
  528. var tw = new TreeWalker(function(node){
  529. if (options.undeclared
  530. && node instanceof AST_SymbolRef
  531. && node.undeclared())
  532. {
  533. // XXX: this also warns about JS standard names,
  534. // i.e. Object, Array, parseInt etc. Should add a list of
  535. // exceptions.
  536. AST_Node.warn("Undeclared symbol: {name} [{file}:{line},{col}]", {
  537. name: node.name,
  538. file: node.start.file,
  539. line: node.start.line,
  540. col: node.start.col
  541. });
  542. }
  543. if (options.assign_to_global)
  544. {
  545. var sym = null;
  546. if (node instanceof AST_Assign && node.left instanceof AST_SymbolRef)
  547. sym = node.left;
  548. else if (node instanceof AST_ForIn && node.init instanceof AST_SymbolRef)
  549. sym = node.init;
  550. if (sym
  551. && (sym.undeclared()
  552. || (sym.global() && sym.scope !== sym.definition().scope))) {
  553. AST_Node.warn("{msg}: {name} [{file}:{line},{col}]", {
  554. msg: sym.undeclared() ? "Accidental global?" : "Assignment to global",
  555. name: sym.name,
  556. file: sym.start.file,
  557. line: sym.start.line,
  558. col: sym.start.col
  559. });
  560. }
  561. }
  562. if (options.eval
  563. && node instanceof AST_SymbolRef
  564. && node.undeclared()
  565. && node.name == "eval") {
  566. AST_Node.warn("Eval is used [{file}:{line},{col}]", node.start);
  567. }
  568. if (options.unreferenced
  569. && (node instanceof AST_SymbolDeclaration || node instanceof AST_Label)
  570. && !(node instanceof AST_SymbolCatch)
  571. && node.unreferenced()) {
  572. AST_Node.warn("{type} {name} is declared but not referenced [{file}:{line},{col}]", {
  573. type: node instanceof AST_Label ? "Label" : "Symbol",
  574. name: node.name,
  575. file: node.start.file,
  576. line: node.start.line,
  577. col: node.start.col
  578. });
  579. }
  580. if (options.func_arguments
  581. && node instanceof AST_Lambda
  582. && node.uses_arguments) {
  583. AST_Node.warn("arguments used in function {name} [{file}:{line},{col}]", {
  584. name: node.name ? node.name.name : "anonymous",
  585. file: node.start.file,
  586. line: node.start.line,
  587. col: node.start.col
  588. });
  589. }
  590. if (options.nested_defuns
  591. && node instanceof AST_Defun
  592. && !(tw.parent() instanceof AST_Scope)) {
  593. AST_Node.warn("Function {name} declared in nested statement \"{type}\" [{file}:{line},{col}]", {
  594. name: node.name.name,
  595. type: tw.parent().TYPE,
  596. file: node.start.file,
  597. line: node.start.line,
  598. col: node.start.col
  599. });
  600. }
  601. });
  602. this.walk(tw);
  603. });