Plugin Directory

Changeset 2615373


Ignore:
Timestamp:
10/17/2021 11:37:20 AM (4 years ago)
Author:
hexydec
Message:

Updated packages.

Location:
torque
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • torque/tags/0.5.6/packages/htmldoc/config.php

    r2592945 r2615373  
    110110                'comments' => [
    111111                    'remove' => true, // remove comments
    112                     'ie' => true // preserve IE comments
     112                    'ie' => false // preserve IE comments
    113113                ],
    114114                'urls' => [ // update internal URL's to be shorter
     
    147147                'quotes' => true, // sets the output option 'quotestyle' to 'minimal'
    148148                'close' => true, // don't write close tags where possible
     149                'safe' => false, // sets the minification presets to CSS safe options
    149150                'email' => false, // sets the minification presets to email safe options
    150151                'style' => [], // specify CSS minifier options
  • torque/tags/0.5.6/packages/htmldoc/htmldoc.php

    r2592945 r2615373  
    598598        }
    599599
     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
    600609        // email minification
    601610        if ($minify['email']) {
     
    697706
    698707    /**
     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    /**
    699742     * Removes all top level nodes, or if $selector is specified, the nodes matched by the selector
    700743     *
  • torque/tags/0.5.6/packages/htmldoc/tokens/tag.php

    r2597073 r2615373  
    288288     *
    289289     * @param array $nodes An array of node objects
     290     * @param int $index To insert the nodes at a particular position, set the index
    290291     * @return void
    291292     */
    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 = [];
    293302        foreach ($nodes AS $item) {
    294303            $child = clone $item;
    295304            $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);
    297315        }
    298316    }
     
    309327            $child->parent = $this;
    310328            \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);
    311362        }
    312363    }
     
    484535
    485536        // 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))) {
    488538            $children = $this->parent->toArray();
    489539            $next = false;
     
    514564
    515565            // if last tag, remove closing tag
    516             if ($next) {
     566            if (!$children || $next) {
    517567                $this->close = false;
    518568            }
  • torque/tags/0.5.6/packages/jslite/jslite.php

    r2592945 r2615373  
    2323
    2424        // 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',
    2626        '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]*+)?+)',
    2828
    2929        // consume strings in quotes, check for escaped quotes
     
    4242
    4343        // capture operators after regexp
    44         'operator' => '[+*\\/<>%&-]?=|[\\.+*!<>:~%|&?^-]+|\\/',
     44        'operator' => '[+*\\/<>%&-]?+=|[\\.+*!<>:~%|&?^-]++|\\/',
    4545
    4646        'whitespace' => '\\s++',
  • torque/tags/0.5.6/packages/jslite/tokens/brackets.php

    r2592945 r2615373  
    2828     */
    2929    public function parse(tokenise $tokens) : bool {
    30         if (($token = $tokens->current()) !== false) {
     30        if (($token = $tokens->current()) !== null) {
    3131            $bracket = $this->bracket = \mb_substr($token['type'], 4);
    3232            while (($token = $tokens->next()) !== null) {
    33                 $obj = new expression($this->bracket);
     33                $obj = new expression($bracket);
    3434                if ($obj->parse($tokens)) {
    3535                    $this->expressions[] = $obj;
     
    7070        // other checks before we remove semi-colon
    7171        if ($last && $minify['semicolons']) {
    72             $key = 'hexydec\\jslite\\keyword';
    73             $bra = 'hexydec\\jslite\\brackets';
     72            $key = __NAMESPACE__.'\\keyword';
     73            $bra = __NAMESPACE__.'\\brackets';
    7474
    7575            // don't remove semi-colon from keyword + brackets with no following commands
  • torque/tags/0.5.6/packages/jslite/tokens/expression.php

    r2592945 r2615373  
    2626            $beforelast = null;
    2727            $last = null;
     28            $assignment = false;
    2829            do {
    2930                switch ($token['type']) {
     
    3940                        if ($obj->parse($tokens)) {
    4041                            $commands[] = $obj;
     42                            if ($token['value'] === '=') {
     43                                $assignment = true;
     44                            }
    4145                        }
    4246                        break;
     
    4852                        break;
    4953                    case 'keyword':
    50                         if ($this->isKeyword($last, $tokens)) {
     54                        if ($this->isKeyword($last, $token, $tokens)) {
    5155                            $obj = new keyword($this);
    5256                            if ($obj->parse($tokens)) {
     
    9094
    9195                            // 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');
    9397                            $tokens->prev(); // move the token pointer back so the operator can be parsed by the normal process
    9498                        }
     
    99103                        // catch un-terminated line endings
    100104                        if ($last && \mb_strpos($token['value'], "\n") !== false) {
    101                             $end = $this->isEol($tokens, $last, $beforelast, $commands);
     105                            $end = $this->isEol($tokens, $last, $beforelast, $assignment);
    102106                        }
    103107
     
    140144    }
    141145
    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
    145153            if (\mb_strpos($next['value'], ':') === 0 || $next['value'] === '.') {
    146154                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                }
    147167            }
    148         } elseif ($last && \get_class($last) === __NAMESPACE__.'\\operator' && $last->content === '.') {
     168        } elseif ($prev && \get_class($prev) === __NAMESPACE__.'\\operator' && $prev->content === '.') {
    149169            return false;
    150170        }
     
    180200     * @return bool Whether the expression should end at the previous command
    181201     */
    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 {
    183203        $prevtype = \get_class($prev);
    184204        $beforeprevtype = $beforeprev ? \get_class($beforeprev) : null;
     
    195215
    196216        // 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)) {
    198218            return false;
    199219
    200220        // if prev is curly then expression will have already ended
    201221        } elseif ($prevtype === $bra && $prev->bracket === 'curly' && $beforeprevtype !== $op) {
    202             return false;
     222            return $assignment;
    203223
    204224        // get next token
     
    206226            return false;
    207227
    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
    209233        } elseif ($prevtype !== $op && $next['type'] === 'keyword') {
    210234            return true;
  • torque/tags/0.5.6/packages/jslite/tokens/whitespace.php

    r2592945 r2615373  
    5656
    5757            // loop through commands
     58            $json = false;
     59            $assignment = false;
     60            $return = false;
    5861            foreach ($commands AS $i => $item) {
    5962                if ($item === $this) {
     
    8487
    8588                                // always terminate return
    86                                 if ($prevtype === $key && !strcasecmp($prev->content, 'return')) {
     89                                if ($return) {
    8790                                    $this->parent->eol = ';';
    8891
    8992                                // 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)) {
    9194                                    $this->parent->eol = ';';
    9295                                }
     
    110113                            $this->content = ' ';
    111114
     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
    112119                        // remove whitespace
    113120                        } else {
     
    116123                    }
    117124                    break;
     125
     126                // record the previous significant objects
    118127                } elseif ($item::significant) {
    119128                    $beforeprev = $prev;
    120129                    $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                    }
    121143                }
    122144            }
  • torque/trunk/packages/htmldoc/config.php

    r2592945 r2615373  
    110110                'comments' => [
    111111                    'remove' => true, // remove comments
    112                     'ie' => true // preserve IE comments
     112                    'ie' => false // preserve IE comments
    113113                ],
    114114                'urls' => [ // update internal URL's to be shorter
     
    147147                'quotes' => true, // sets the output option 'quotestyle' to 'minimal'
    148148                'close' => true, // don't write close tags where possible
     149                'safe' => false, // sets the minification presets to CSS safe options
    149150                'email' => false, // sets the minification presets to email safe options
    150151                'style' => [], // specify CSS minifier options
  • torque/trunk/packages/htmldoc/htmldoc.php

    r2592945 r2615373  
    598598        }
    599599
     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
    600609        // email minification
    601610        if ($minify['email']) {
     
    697706
    698707    /**
     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    /**
    699742     * Removes all top level nodes, or if $selector is specified, the nodes matched by the selector
    700743     *
  • torque/trunk/packages/htmldoc/tokens/tag.php

    r2597073 r2615373  
    288288     *
    289289     * @param array $nodes An array of node objects
     290     * @param int $index To insert the nodes at a particular position, set the index
    290291     * @return void
    291292     */
    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 = [];
    293302        foreach ($nodes AS $item) {
    294303            $child = clone $item;
    295304            $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);
    297315        }
    298316    }
     
    309327            $child->parent = $this;
    310328            \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);
    311362        }
    312363    }
     
    484535
    485536        // 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))) {
    488538            $children = $this->parent->toArray();
    489539            $next = false;
     
    514564
    515565            // if last tag, remove closing tag
    516             if ($next) {
     566            if (!$children || $next) {
    517567                $this->close = false;
    518568            }
  • torque/trunk/packages/jslite/jslite.php

    r2592945 r2615373  
    2323
    2424        // 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',
    2626        '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]*+)?+)',
    2828
    2929        // consume strings in quotes, check for escaped quotes
     
    4242
    4343        // capture operators after regexp
    44         'operator' => '[+*\\/<>%&-]?=|[\\.+*!<>:~%|&?^-]+|\\/',
     44        'operator' => '[+*\\/<>%&-]?+=|[\\.+*!<>:~%|&?^-]++|\\/',
    4545
    4646        'whitespace' => '\\s++',
  • torque/trunk/packages/jslite/tokens/brackets.php

    r2592945 r2615373  
    2828     */
    2929    public function parse(tokenise $tokens) : bool {
    30         if (($token = $tokens->current()) !== false) {
     30        if (($token = $tokens->current()) !== null) {
    3131            $bracket = $this->bracket = \mb_substr($token['type'], 4);
    3232            while (($token = $tokens->next()) !== null) {
    33                 $obj = new expression($this->bracket);
     33                $obj = new expression($bracket);
    3434                if ($obj->parse($tokens)) {
    3535                    $this->expressions[] = $obj;
     
    7070        // other checks before we remove semi-colon
    7171        if ($last && $minify['semicolons']) {
    72             $key = 'hexydec\\jslite\\keyword';
    73             $bra = 'hexydec\\jslite\\brackets';
     72            $key = __NAMESPACE__.'\\keyword';
     73            $bra = __NAMESPACE__.'\\brackets';
    7474
    7575            // don't remove semi-colon from keyword + brackets with no following commands
  • torque/trunk/packages/jslite/tokens/expression.php

    r2592945 r2615373  
    2626            $beforelast = null;
    2727            $last = null;
     28            $assignment = false;
    2829            do {
    2930                switch ($token['type']) {
     
    3940                        if ($obj->parse($tokens)) {
    4041                            $commands[] = $obj;
     42                            if ($token['value'] === '=') {
     43                                $assignment = true;
     44                            }
    4145                        }
    4246                        break;
     
    4852                        break;
    4953                    case 'keyword':
    50                         if ($this->isKeyword($last, $tokens)) {
     54                        if ($this->isKeyword($last, $token, $tokens)) {
    5155                            $obj = new keyword($this);
    5256                            if ($obj->parse($tokens)) {
     
    9094
    9195                            // 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');
    9397                            $tokens->prev(); // move the token pointer back so the operator can be parsed by the normal process
    9498                        }
     
    99103                        // catch un-terminated line endings
    100104                        if ($last && \mb_strpos($token['value'], "\n") !== false) {
    101                             $end = $this->isEol($tokens, $last, $beforelast, $commands);
     105                            $end = $this->isEol($tokens, $last, $beforelast, $assignment);
    102106                        }
    103107
     
    140144    }
    141145
    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
    145153            if (\mb_strpos($next['value'], ':') === 0 || $next['value'] === '.') {
    146154                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                }
    147167            }
    148         } elseif ($last && \get_class($last) === __NAMESPACE__.'\\operator' && $last->content === '.') {
     168        } elseif ($prev && \get_class($prev) === __NAMESPACE__.'\\operator' && $prev->content === '.') {
    149169            return false;
    150170        }
     
    180200     * @return bool Whether the expression should end at the previous command
    181201     */
    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 {
    183203        $prevtype = \get_class($prev);
    184204        $beforeprevtype = $beforeprev ? \get_class($beforeprev) : null;
     
    195215
    196216        // 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)) {
    198218            return false;
    199219
    200220        // if prev is curly then expression will have already ended
    201221        } elseif ($prevtype === $bra && $prev->bracket === 'curly' && $beforeprevtype !== $op) {
    202             return false;
     222            return $assignment;
    203223
    204224        // get next token
     
    206226            return false;
    207227
    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
    209233        } elseif ($prevtype !== $op && $next['type'] === 'keyword') {
    210234            return true;
  • torque/trunk/packages/jslite/tokens/whitespace.php

    r2592945 r2615373  
    5656
    5757            // loop through commands
     58            $json = false;
     59            $assignment = false;
     60            $return = false;
    5861            foreach ($commands AS $i => $item) {
    5962                if ($item === $this) {
     
    8487
    8588                                // always terminate return
    86                                 if ($prevtype === $key && !strcasecmp($prev->content, 'return')) {
     89                                if ($return) {
    8790                                    $this->parent->eol = ';';
    8891
    8992                                // 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)) {
    9194                                    $this->parent->eol = ';';
    9295                                }
     
    110113                            $this->content = ' ';
    111114
     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
    112119                        // remove whitespace
    113120                        } else {
     
    116123                    }
    117124                    break;
     125
     126                // record the previous significant objects
    118127                } elseif ($item::significant) {
    119128                    $beforeprev = $prev;
    120129                    $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                    }
    121143                }
    122144            }
Note: See TracChangeset for help on using the changeset viewer.