Changeset 2615373
- Timestamp:
- 10/17/2021 11:37:20 AM (4 years ago)
- Location:
- torque
- Files:
-
- 14 edited
-
tags/0.5.6/packages/htmldoc/config.php (modified) (2 diffs)
-
tags/0.5.6/packages/htmldoc/htmldoc.php (modified) (2 diffs)
-
tags/0.5.6/packages/htmldoc/tokens/tag.php (modified) (4 diffs)
-
tags/0.5.6/packages/jslite/jslite.php (modified) (2 diffs)
-
tags/0.5.6/packages/jslite/tokens/brackets.php (modified) (2 diffs)
-
tags/0.5.6/packages/jslite/tokens/expression.php (modified) (9 diffs)
-
tags/0.5.6/packages/jslite/tokens/whitespace.php (modified) (4 diffs)
-
trunk/packages/htmldoc/config.php (modified) (2 diffs)
-
trunk/packages/htmldoc/htmldoc.php (modified) (2 diffs)
-
trunk/packages/htmldoc/tokens/tag.php (modified) (4 diffs)
-
trunk/packages/jslite/jslite.php (modified) (2 diffs)
-
trunk/packages/jslite/tokens/brackets.php (modified) (2 diffs)
-
trunk/packages/jslite/tokens/expression.php (modified) (9 diffs)
-
trunk/packages/jslite/tokens/whitespace.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
torque/tags/0.5.6/packages/htmldoc/config.php
r2592945 r2615373 110 110 'comments' => [ 111 111 'remove' => true, // remove comments 112 'ie' => true // preserve IE comments112 'ie' => false // preserve IE comments 113 113 ], 114 114 'urls' => [ // update internal URL's to be shorter … … 147 147 'quotes' => true, // sets the output option 'quotestyle' to 'minimal' 148 148 'close' => true, // don't write close tags where possible 149 'safe' => false, // sets the minification presets to CSS safe options 149 150 'email' => false, // sets the minification presets to email safe options 150 151 'style' => [], // specify CSS minifier options -
torque/tags/0.5.6/packages/htmldoc/htmldoc.php
r2592945 r2615373 598 598 } 599 599 600 // set safe options 601 if ($minify['safe']) { 602 $minify['urls'] = false; 603 if ($minify['attributes'] !== false) { 604 $minify['attributes']['empty'] = false; 605 $minify['attributes']['default'] = false; 606 } 607 } 608 600 609 // email minification 601 610 if ($minify['email']) { … … 697 706 698 707 /** 708 * Insert an array of nodes before the each node in the current document 709 * 710 * @param string|htmldoc $html A string of HTML, or an htmldoc object 711 * @return htmldoc The current htmldoc object with the nodes appended 712 */ 713 public function before($html) : htmldoc { 714 if (($nodes = $this->parse($html)) !== false) { 715 foreach ($this->children AS $item) { 716 if (\get_class($item) === 'hexydec\\html\\tag') { 717 $item->before($nodes); 718 } 719 } 720 } 721 return $this; 722 } 723 724 /** 725 * Insert an array of nodes after the each node in the current document 726 * 727 * @param string|htmldoc $html A string of HTML, or an htmldoc object 728 * @return htmldoc The current htmldoc object with the nodes appended 729 */ 730 public function after($html) : htmldoc { 731 if (($nodes = $this->parse($html)) !== false) { 732 foreach ($this->children AS $item) { 733 if (\get_class($item) === 'hexydec\\html\\tag') { 734 $item->after($nodes); 735 } 736 } 737 } 738 return $this; 739 } 740 741 /** 699 742 * Removes all top level nodes, or if $selector is specified, the nodes matched by the selector 700 743 * -
torque/tags/0.5.6/packages/htmldoc/tokens/tag.php
r2597073 r2615373 288 288 * 289 289 * @param array $nodes An array of node objects 290 * @param int $index To insert the nodes at a particular position, set the index 290 291 * @return void 291 292 */ 292 public function append(array $nodes) : void { 293 public function append(array $nodes, int $index = null) : void { 294 295 // reset the index if it doesn't exist 296 if ($index !== null && !isset($this->children[$index])) { 297 $index = null; 298 } 299 300 // clone the nodes 301 $clones = []; 293 302 foreach ($nodes AS $item) { 294 303 $child = clone $item; 295 304 $child->parent = $this; 296 $this->children[] = $child; 305 if ($index === null) { 306 $this->children[] = $child; 307 } else { 308 $clones[] = $child; 309 } 310 } 311 312 // insert the nodes 313 if ($index !== null) { 314 $this->chidren = \array_splice($this->children, $index, 0, $clones); 297 315 } 298 316 } … … 309 327 $child->parent = $this; 310 328 \array_unshift($this->children, $child); 329 } 330 } 331 332 protected function getIndex() : ?int { 333 foreach ($this->parent->children() AS $key => $item) { 334 if ($item === $this) { 335 return $key; 336 } 337 } 338 return null; 339 } 340 341 /** 342 * Insert an array of nodes before the current node 343 * 344 * @param array $nodes An array of node objects 345 * @return void 346 */ 347 public function before(array $nodes) : void { 348 if (($index = $this->getIndex()) !== null) { 349 $this->parent->append($nodes, $index); 350 } 351 } 352 353 /** 354 * Insert an array of nodes after the current node 355 * 356 * @param array $nodes An array of node objects 357 * @return void 358 */ 359 public function after(array $nodes) : void { 360 if (($index = $this->getIndex()) !== null) { 361 $this->parent->append($nodes, $index + 1); 311 362 } 312 363 } … … 484 535 485 536 // work out whether to omit the closing tag 486 if ($minify['close'] && \in_array($tag, $config['elements']['closeoptional']) && !\in_array($this->parent->tagName, $config['elements']['inline'], true)) { 487 $tag = null; 537 if ($minify['close'] && \in_array($tag, $config['elements']['closeoptional']) && ($this->parent->tagName === null || !\in_array($this->parent->tagName, $config['elements']['inline'], true))) { 488 538 $children = $this->parent->toArray(); 489 539 $next = false; … … 514 564 515 565 // if last tag, remove closing tag 516 if ( $next) {566 if (!$children || $next) { 517 567 $this->close = false; 518 568 } -
torque/tags/0.5.6/packages/jslite/jslite.php
r2592945 r2615373 23 23 24 24 // keywords number and variables 25 'keyword' => '\\b(?: (?i)let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b',25 'keyword' => '\\b(?:let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b', 26 26 'variable' => '[\\p{L}\\p{Nl}$_][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$_]*+', 27 'number' => '(?:0[bB][01_]++n?|0[oO][0-7_]++n?|0[xX][a-f0-9_]|[0-9][0-9_]*+(?:\\.[0-9_]++)? (?:e[+-]?[1-9][0-9]*+)?)',27 'number' => '(?:0[bB][01_]++n?|0[oO][0-7_]++n?|0[xX][a-f0-9_]|[0-9][0-9_]*+(?:\\.[0-9_]++)?+(?:e[+-]?[1-9][0-9]*+)?+)', 28 28 29 29 // consume strings in quotes, check for escaped quotes … … 42 42 43 43 // capture operators after regexp 44 'operator' => '[+*\\/<>%&-]? =|[\\.+*!<>:~%|&?^-]+|\\/',44 'operator' => '[+*\\/<>%&-]?+=|[\\.+*!<>:~%|&?^-]++|\\/', 45 45 46 46 'whitespace' => '\\s++', -
torque/tags/0.5.6/packages/jslite/tokens/brackets.php
r2592945 r2615373 28 28 */ 29 29 public function parse(tokenise $tokens) : bool { 30 if (($token = $tokens->current()) !== false) {30 if (($token = $tokens->current()) !== null) { 31 31 $bracket = $this->bracket = \mb_substr($token['type'], 4); 32 32 while (($token = $tokens->next()) !== null) { 33 $obj = new expression($ this->bracket);33 $obj = new expression($bracket); 34 34 if ($obj->parse($tokens)) { 35 35 $this->expressions[] = $obj; … … 70 70 // other checks before we remove semi-colon 71 71 if ($last && $minify['semicolons']) { 72 $key = 'hexydec\\jslite\\keyword';73 $bra = 'hexydec\\jslite\\brackets';72 $key = __NAMESPACE__.'\\keyword'; 73 $bra = __NAMESPACE__.'\\brackets'; 74 74 75 75 // don't remove semi-colon from keyword + brackets with no following commands -
torque/tags/0.5.6/packages/jslite/tokens/expression.php
r2592945 r2615373 26 26 $beforelast = null; 27 27 $last = null; 28 $assignment = false; 28 29 do { 29 30 switch ($token['type']) { … … 39 40 if ($obj->parse($tokens)) { 40 41 $commands[] = $obj; 42 if ($token['value'] === '=') { 43 $assignment = true; 44 } 41 45 } 42 46 break; … … 48 52 break; 49 53 case 'keyword': 50 if ($this->isKeyword($last, $token s)) {54 if ($this->isKeyword($last, $token, $tokens)) { 51 55 $obj = new keyword($this); 52 56 if ($obj->parse($tokens)) { … … 90 94 91 95 // rewind the tokeniser to start the next parse loop from after the divide 92 $tokens->rewind( mb_strlen($token['value'])-1, 'operator');96 $tokens->rewind(\mb_strlen($token['value'])-1, 'operator'); 93 97 $tokens->prev(); // move the token pointer back so the operator can be parsed by the normal process 94 98 } … … 99 103 // catch un-terminated line endings 100 104 if ($last && \mb_strpos($token['value'], "\n") !== false) { 101 $end = $this->isEol($tokens, $last, $beforelast, $ commands);105 $end = $this->isEol($tokens, $last, $beforelast, $assignment); 102 106 } 103 107 … … 140 144 } 141 145 142 protected function isKeyword($last, tokenise $tokens) { 143 if (($next = $tokens->next(null, false)) !== null) { 144 $tokens->prev(); 146 /** 147 * Works out whether a keyword is legal in the current context 148 */ 149 protected function isKeyword($prev, array $current, tokenise $tokens) { 150 if (($next = $this->getNextSignificantToken($tokens)) !== null) { 151 152 // property name 145 153 if (\mb_strpos($next['value'], ':') === 0 || $next['value'] === '.') { 146 154 return false; 155 156 // var undefined 157 } elseif ($current['value'] === 'undefined') { 158 159 // is a variable definition 160 if ($prev && \in_array($prev->content, ['const', 'let', 'var'])) { 161 return false; 162 163 // followed by an assignment, comma, or EOL 164 } elseif (!$prev && \in_array($next['value'], ['=', ',', ';'])) { 165 return false; 166 } 147 167 } 148 } elseif ($ last && \get_class($last) === __NAMESPACE__.'\\operator' && $last->content === '.') {168 } elseif ($prev && \get_class($prev) === __NAMESPACE__.'\\operator' && $prev->content === '.') { 149 169 return false; 150 170 } … … 180 200 * @return bool Whether the expression should end at the previous command 181 201 */ 182 protected function isEol(tokenise $tokens, $prev = null, $beforeprev = null ) : bool {202 protected function isEol(tokenise $tokens, $prev = null, $beforeprev = null, bool $assignment = false) : bool { 183 203 $prevtype = \get_class($prev); 184 204 $beforeprevtype = $beforeprev ? \get_class($beforeprev) : null; … … 195 215 196 216 // special case for keyword followed by bracket 197 } elseif ($prevtype === $bra && $beforeprev && $beforeprevtype === $key) {217 } elseif ($prevtype === $bra && $beforeprevtype === $key && !\in_array($beforeprev->content, $keywords, true)) { 198 218 return false; 199 219 200 220 // if prev is curly then expression will have already ended 201 221 } elseif ($prevtype === $bra && $prev->bracket === 'curly' && $beforeprevtype !== $op) { 202 return false;222 return $assignment; 203 223 204 224 // get next token … … 206 226 return false; 207 227 208 // next expression starts with a semi-colon 228 // if the previous expression is an operator, like + or =, then the expression must end if next not an operator 229 } elseif ($beforeprevtype === $op && !\in_array($next['type'], ['operator', 'openbracket', 'eol'])) { 230 return true; 231 232 // next expression starts with a keyword 209 233 } elseif ($prevtype !== $op && $next['type'] === 'keyword') { 210 234 return true; -
torque/tags/0.5.6/packages/jslite/tokens/whitespace.php
r2592945 r2615373 56 56 57 57 // loop through commands 58 $json = false; 59 $assignment = false; 60 $return = false; 58 61 foreach ($commands AS $i => $item) { 59 62 if ($item === $this) { … … 84 87 85 88 // always terminate return 86 if ($ prevtype === $key && !strcasecmp($prev->content, 'return')) {89 if ($return) { 87 90 $this->parent->eol = ';'; 88 91 89 92 // only terminate if not object 90 } elseif ( $this->parent->bracket !== 'curly' || empty($beforeprev->content) || $beforeprev->content !== ':') {93 } elseif (!\in_array($this->parent->bracket, ['square', 'bracket'], true) && ($this->parent->bracket !== 'curly' || !$json)) { 91 94 $this->parent->eol = ';'; 92 95 } … … 110 113 $this->content = ' '; 111 114 115 // special case for when return true is converted to return !0, causes the whitespace to flip 116 } elseif ($prevtype === $key && \mb_strpos($next->compile(), '!') === 0) { 117 $this->content = ' '; 118 112 119 // remove whitespace 113 120 } else { … … 116 123 } 117 124 break; 125 126 // record the previous significant objects 118 127 } elseif ($item::significant) { 119 128 $beforeprev = $prev; 120 129 $prev = $item; 130 131 // return statement 132 if (($item->content ?? null) === 'return') { 133 $return = true; 134 135 // track assignemt types 136 } elseif (($item->content ?? null) === '?') { 137 $assignment = true; 138 139 // not allowed if already assigned - ternary 140 } elseif (!$assignment && ($item->content ?? null) === ':') { 141 $json = true; 142 } 121 143 } 122 144 } -
torque/trunk/packages/htmldoc/config.php
r2592945 r2615373 110 110 'comments' => [ 111 111 'remove' => true, // remove comments 112 'ie' => true // preserve IE comments112 'ie' => false // preserve IE comments 113 113 ], 114 114 'urls' => [ // update internal URL's to be shorter … … 147 147 'quotes' => true, // sets the output option 'quotestyle' to 'minimal' 148 148 'close' => true, // don't write close tags where possible 149 'safe' => false, // sets the minification presets to CSS safe options 149 150 'email' => false, // sets the minification presets to email safe options 150 151 'style' => [], // specify CSS minifier options -
torque/trunk/packages/htmldoc/htmldoc.php
r2592945 r2615373 598 598 } 599 599 600 // set safe options 601 if ($minify['safe']) { 602 $minify['urls'] = false; 603 if ($minify['attributes'] !== false) { 604 $minify['attributes']['empty'] = false; 605 $minify['attributes']['default'] = false; 606 } 607 } 608 600 609 // email minification 601 610 if ($minify['email']) { … … 697 706 698 707 /** 708 * Insert an array of nodes before the each node in the current document 709 * 710 * @param string|htmldoc $html A string of HTML, or an htmldoc object 711 * @return htmldoc The current htmldoc object with the nodes appended 712 */ 713 public function before($html) : htmldoc { 714 if (($nodes = $this->parse($html)) !== false) { 715 foreach ($this->children AS $item) { 716 if (\get_class($item) === 'hexydec\\html\\tag') { 717 $item->before($nodes); 718 } 719 } 720 } 721 return $this; 722 } 723 724 /** 725 * Insert an array of nodes after the each node in the current document 726 * 727 * @param string|htmldoc $html A string of HTML, or an htmldoc object 728 * @return htmldoc The current htmldoc object with the nodes appended 729 */ 730 public function after($html) : htmldoc { 731 if (($nodes = $this->parse($html)) !== false) { 732 foreach ($this->children AS $item) { 733 if (\get_class($item) === 'hexydec\\html\\tag') { 734 $item->after($nodes); 735 } 736 } 737 } 738 return $this; 739 } 740 741 /** 699 742 * Removes all top level nodes, or if $selector is specified, the nodes matched by the selector 700 743 * -
torque/trunk/packages/htmldoc/tokens/tag.php
r2597073 r2615373 288 288 * 289 289 * @param array $nodes An array of node objects 290 * @param int $index To insert the nodes at a particular position, set the index 290 291 * @return void 291 292 */ 292 public function append(array $nodes) : void { 293 public function append(array $nodes, int $index = null) : void { 294 295 // reset the index if it doesn't exist 296 if ($index !== null && !isset($this->children[$index])) { 297 $index = null; 298 } 299 300 // clone the nodes 301 $clones = []; 293 302 foreach ($nodes AS $item) { 294 303 $child = clone $item; 295 304 $child->parent = $this; 296 $this->children[] = $child; 305 if ($index === null) { 306 $this->children[] = $child; 307 } else { 308 $clones[] = $child; 309 } 310 } 311 312 // insert the nodes 313 if ($index !== null) { 314 $this->chidren = \array_splice($this->children, $index, 0, $clones); 297 315 } 298 316 } … … 309 327 $child->parent = $this; 310 328 \array_unshift($this->children, $child); 329 } 330 } 331 332 protected function getIndex() : ?int { 333 foreach ($this->parent->children() AS $key => $item) { 334 if ($item === $this) { 335 return $key; 336 } 337 } 338 return null; 339 } 340 341 /** 342 * Insert an array of nodes before the current node 343 * 344 * @param array $nodes An array of node objects 345 * @return void 346 */ 347 public function before(array $nodes) : void { 348 if (($index = $this->getIndex()) !== null) { 349 $this->parent->append($nodes, $index); 350 } 351 } 352 353 /** 354 * Insert an array of nodes after the current node 355 * 356 * @param array $nodes An array of node objects 357 * @return void 358 */ 359 public function after(array $nodes) : void { 360 if (($index = $this->getIndex()) !== null) { 361 $this->parent->append($nodes, $index + 1); 311 362 } 312 363 } … … 484 535 485 536 // work out whether to omit the closing tag 486 if ($minify['close'] && \in_array($tag, $config['elements']['closeoptional']) && !\in_array($this->parent->tagName, $config['elements']['inline'], true)) { 487 $tag = null; 537 if ($minify['close'] && \in_array($tag, $config['elements']['closeoptional']) && ($this->parent->tagName === null || !\in_array($this->parent->tagName, $config['elements']['inline'], true))) { 488 538 $children = $this->parent->toArray(); 489 539 $next = false; … … 514 564 515 565 // if last tag, remove closing tag 516 if ( $next) {566 if (!$children || $next) { 517 567 $this->close = false; 518 568 } -
torque/trunk/packages/jslite/jslite.php
r2592945 r2615373 23 23 24 24 // keywords number and variables 25 'keyword' => '\\b(?: (?i)let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b',25 'keyword' => '\\b(?:let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b', 26 26 'variable' => '[\\p{L}\\p{Nl}$_][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$_]*+', 27 'number' => '(?:0[bB][01_]++n?|0[oO][0-7_]++n?|0[xX][a-f0-9_]|[0-9][0-9_]*+(?:\\.[0-9_]++)? (?:e[+-]?[1-9][0-9]*+)?)',27 'number' => '(?:0[bB][01_]++n?|0[oO][0-7_]++n?|0[xX][a-f0-9_]|[0-9][0-9_]*+(?:\\.[0-9_]++)?+(?:e[+-]?[1-9][0-9]*+)?+)', 28 28 29 29 // consume strings in quotes, check for escaped quotes … … 42 42 43 43 // capture operators after regexp 44 'operator' => '[+*\\/<>%&-]? =|[\\.+*!<>:~%|&?^-]+|\\/',44 'operator' => '[+*\\/<>%&-]?+=|[\\.+*!<>:~%|&?^-]++|\\/', 45 45 46 46 'whitespace' => '\\s++', -
torque/trunk/packages/jslite/tokens/brackets.php
r2592945 r2615373 28 28 */ 29 29 public function parse(tokenise $tokens) : bool { 30 if (($token = $tokens->current()) !== false) {30 if (($token = $tokens->current()) !== null) { 31 31 $bracket = $this->bracket = \mb_substr($token['type'], 4); 32 32 while (($token = $tokens->next()) !== null) { 33 $obj = new expression($ this->bracket);33 $obj = new expression($bracket); 34 34 if ($obj->parse($tokens)) { 35 35 $this->expressions[] = $obj; … … 70 70 // other checks before we remove semi-colon 71 71 if ($last && $minify['semicolons']) { 72 $key = 'hexydec\\jslite\\keyword';73 $bra = 'hexydec\\jslite\\brackets';72 $key = __NAMESPACE__.'\\keyword'; 73 $bra = __NAMESPACE__.'\\brackets'; 74 74 75 75 // don't remove semi-colon from keyword + brackets with no following commands -
torque/trunk/packages/jslite/tokens/expression.php
r2592945 r2615373 26 26 $beforelast = null; 27 27 $last = null; 28 $assignment = false; 28 29 do { 29 30 switch ($token['type']) { … … 39 40 if ($obj->parse($tokens)) { 40 41 $commands[] = $obj; 42 if ($token['value'] === '=') { 43 $assignment = true; 44 } 41 45 } 42 46 break; … … 48 52 break; 49 53 case 'keyword': 50 if ($this->isKeyword($last, $token s)) {54 if ($this->isKeyword($last, $token, $tokens)) { 51 55 $obj = new keyword($this); 52 56 if ($obj->parse($tokens)) { … … 90 94 91 95 // rewind the tokeniser to start the next parse loop from after the divide 92 $tokens->rewind( mb_strlen($token['value'])-1, 'operator');96 $tokens->rewind(\mb_strlen($token['value'])-1, 'operator'); 93 97 $tokens->prev(); // move the token pointer back so the operator can be parsed by the normal process 94 98 } … … 99 103 // catch un-terminated line endings 100 104 if ($last && \mb_strpos($token['value'], "\n") !== false) { 101 $end = $this->isEol($tokens, $last, $beforelast, $ commands);105 $end = $this->isEol($tokens, $last, $beforelast, $assignment); 102 106 } 103 107 … … 140 144 } 141 145 142 protected function isKeyword($last, tokenise $tokens) { 143 if (($next = $tokens->next(null, false)) !== null) { 144 $tokens->prev(); 146 /** 147 * Works out whether a keyword is legal in the current context 148 */ 149 protected function isKeyword($prev, array $current, tokenise $tokens) { 150 if (($next = $this->getNextSignificantToken($tokens)) !== null) { 151 152 // property name 145 153 if (\mb_strpos($next['value'], ':') === 0 || $next['value'] === '.') { 146 154 return false; 155 156 // var undefined 157 } elseif ($current['value'] === 'undefined') { 158 159 // is a variable definition 160 if ($prev && \in_array($prev->content, ['const', 'let', 'var'])) { 161 return false; 162 163 // followed by an assignment, comma, or EOL 164 } elseif (!$prev && \in_array($next['value'], ['=', ',', ';'])) { 165 return false; 166 } 147 167 } 148 } elseif ($ last && \get_class($last) === __NAMESPACE__.'\\operator' && $last->content === '.') {168 } elseif ($prev && \get_class($prev) === __NAMESPACE__.'\\operator' && $prev->content === '.') { 149 169 return false; 150 170 } … … 180 200 * @return bool Whether the expression should end at the previous command 181 201 */ 182 protected function isEol(tokenise $tokens, $prev = null, $beforeprev = null ) : bool {202 protected function isEol(tokenise $tokens, $prev = null, $beforeprev = null, bool $assignment = false) : bool { 183 203 $prevtype = \get_class($prev); 184 204 $beforeprevtype = $beforeprev ? \get_class($beforeprev) : null; … … 195 215 196 216 // special case for keyword followed by bracket 197 } elseif ($prevtype === $bra && $beforeprev && $beforeprevtype === $key) {217 } elseif ($prevtype === $bra && $beforeprevtype === $key && !\in_array($beforeprev->content, $keywords, true)) { 198 218 return false; 199 219 200 220 // if prev is curly then expression will have already ended 201 221 } elseif ($prevtype === $bra && $prev->bracket === 'curly' && $beforeprevtype !== $op) { 202 return false;222 return $assignment; 203 223 204 224 // get next token … … 206 226 return false; 207 227 208 // next expression starts with a semi-colon 228 // if the previous expression is an operator, like + or =, then the expression must end if next not an operator 229 } elseif ($beforeprevtype === $op && !\in_array($next['type'], ['operator', 'openbracket', 'eol'])) { 230 return true; 231 232 // next expression starts with a keyword 209 233 } elseif ($prevtype !== $op && $next['type'] === 'keyword') { 210 234 return true; -
torque/trunk/packages/jslite/tokens/whitespace.php
r2592945 r2615373 56 56 57 57 // loop through commands 58 $json = false; 59 $assignment = false; 60 $return = false; 58 61 foreach ($commands AS $i => $item) { 59 62 if ($item === $this) { … … 84 87 85 88 // always terminate return 86 if ($ prevtype === $key && !strcasecmp($prev->content, 'return')) {89 if ($return) { 87 90 $this->parent->eol = ';'; 88 91 89 92 // only terminate if not object 90 } elseif ( $this->parent->bracket !== 'curly' || empty($beforeprev->content) || $beforeprev->content !== ':') {93 } elseif (!\in_array($this->parent->bracket, ['square', 'bracket'], true) && ($this->parent->bracket !== 'curly' || !$json)) { 91 94 $this->parent->eol = ';'; 92 95 } … … 110 113 $this->content = ' '; 111 114 115 // special case for when return true is converted to return !0, causes the whitespace to flip 116 } elseif ($prevtype === $key && \mb_strpos($next->compile(), '!') === 0) { 117 $this->content = ' '; 118 112 119 // remove whitespace 113 120 } else { … … 116 123 } 117 124 break; 125 126 // record the previous significant objects 118 127 } elseif ($item::significant) { 119 128 $beforeprev = $prev; 120 129 $prev = $item; 130 131 // return statement 132 if (($item->content ?? null) === 'return') { 133 $return = true; 134 135 // track assignemt types 136 } elseif (($item->content ?? null) === '?') { 137 $assignment = true; 138 139 // not allowed if already assigned - ternary 140 } elseif (!$assignment && ($item->content ?? null) === ':') { 141 $json = true; 142 } 121 143 } 122 144 }
Note: See TracChangeset
for help on using the changeset viewer.