Skip to content

Commit

Permalink
(U) add support for Glimmer TypeScript, #828 part 2 of 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed May 11, 2024
1 parent 97a71c4 commit 333d6bf
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -5792,15 +5792,18 @@ sub invoke_generator { # {{{1
if ($opt_fullpath and any_match($F, 0, \$rule, @opt_not_match_d)) {
$Ignored{$F} = "--not-match-d=$rule";
next;
} elsif (any_match(basename($F), 0, \$rule, @opt_not_match_d)) {
} elsif (!$opt_fullpath and any_match(basename($F), 0, \$rule, @opt_not_match_d)) {
$Ignored{$F} = "--not-match-d (basename) =$rule";
next;
}
}
if (@opt_not_match_f) {
my $rule;
if (any_match(basename($F), 0, \$rule, @opt_not_match_f)) {
$Ignored{$F} = "--not-match-d =$rule";
if ($opt_fullpath and any_match($F, 0, \$rule, @opt_not_match_f)) {
$Ignored{$F} = "--not-match-f=$rule";
next;
} elsif (!$opt_fullpath and any_match(basename($F), 0, \$rule, @opt_not_match_f)) {
$Ignored{$F} = "--not-match-f (basename) =$rule";
next;
}
}
Expand Down Expand Up @@ -8432,6 +8435,7 @@ sub set_constants { # {{{1
'fp' => 'GLSL' ,
'fbs' => 'Flatbuffers' ,
'gjs' => 'Glimmer JavaScript' ,
'gts' => 'Glimmer TypeScript' ,
'glsl' => 'GLSL' ,
'graphqls' => 'GraphQL' ,
'gql' => 'GraphQL' ,
Expand Down Expand Up @@ -9718,6 +9722,15 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Glimmer TypeScript' => [
[ 'remove_between_general', '{{!', '}}' ],
[ 'remove_between_general', '<!--', '-->' ],
[ 'rm_comments_in_strings', "'", '/*', '*/' ],
[ 'rm_comments_in_strings', "'", '//', '' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'GLSL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
Expand Down Expand Up @@ -11186,6 +11199,7 @@ sub set_constants { # {{{1
'Gleam' => 2.50,
'GLSL' => 2.00,
'Glimmer JavaScript' => 3.50,
'Glimmer TypeScript' => 3.50,
'gml' => 1.74,
'gpss' => 1.74,
'guest' => 2.86,
Expand Down
5 changes: 5 additions & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ my @Tests = (
'ref' => '../tests/outputs/body.gjs.yaml',
'args' => '../tests/inputs/body.gjs',
},
{
'name' => 'Glimmer TypeScript',
'ref' => '../tests/outputs/input.gts.yaml',
'args' => '../tests/inputs/input.gts',
},
{
'name' => 'GLSL',
'ref' => '../tests/outputs/blur.glsl.yaml',
Expand Down
11 changes: 11 additions & 0 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -8450,6 +8450,7 @@ sub set_constants { # {{{1
'fp' => 'GLSL' ,
'fbs' => 'Flatbuffers' ,
'gjs' => 'Glimmer JavaScript' ,
'gts' => 'Glimmer TypeScript' ,
'glsl' => 'GLSL' ,
'graphqls' => 'GraphQL' ,
'gql' => 'GraphQL' ,
Expand Down Expand Up @@ -9736,6 +9737,15 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Glimmer TypeScript' => [
[ 'remove_between_general', '{{!', '}}' ],
[ 'remove_between_general', '<!--', '-->' ],
[ 'rm_comments_in_strings', "'", '/*', '*/' ],
[ 'rm_comments_in_strings', "'", '//', '' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'GLSL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
Expand Down Expand Up @@ -11204,6 +11214,7 @@ sub set_constants { # {{{1
'Gleam' => 2.50,
'GLSL' => 2.00,
'Glimmer JavaScript' => 3.50,
'Glimmer TypeScript' => 3.50,
'gml' => 1.74,
'gpss' => 1.74,
'guest' => 2.86,
Expand Down
150 changes: 150 additions & 0 deletions tests/inputs/input.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{{! partial of
https://raw.githubusercontent.com/josemarluedke/frontile/a9680f2681a8b1193feba0fdc27871566bcde120/packages/forms/src/components/input.gts
}}
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import {
useStyles,
type InputSlots,
type InputVariants,
type SlotsToClasses
} from '@frontile/theme';
import { FormControl, type FormControlSharedArgs } from './form-control';
import { triggerFormInputEvent } from '../utils';
import { ref } from '@frontile/utilities';
import { CloseButton } from '@frontile/buttons';

interface Args extends FormControlSharedArgs {
type?: string;
value?: string;
name?: string;
size?: InputVariants['size'];
classes?: SlotsToClasses<InputSlots>;

/**
* Whether to include a clear button
*/
isClearable?: boolean;

/**
* Controls pointer-events property of startContent.
* If you want to pass the click event to the input, set it to `none`.
*
* @defaultValue 'auto'
*/
startContentPointerEvents?: 'none' | 'auto';

/**
* Controls pointer-events property of endContent.
* If you want to pass the click event to the input, set it to `none`.
*
* @defaultValue 'auto'
*/
endContentPointerEvents?: 'none' | 'auto';

/**
* Callback when oninput is triggered
*/
onInput?: (value: string, event?: InputEvent) => void;

/**
* Callback when onchange is triggered
*/
onChange?: (value: string, event?: InputEvent) => void;
}

interface InputSignature {
Args: Args;
Blocks: {
startContent: [];
endContent: [];
};
Element: HTMLInputElement;
}

function or(arg1: unknown, arg2: unknown): boolean {
return !!(arg1 || arg2);
}

class Input extends Component<InputSignature> {
@tracked uncontrolledValue: string = '';

inputRef = ref<HTMLInputElement>();

if (this.isControlled) {
this.args.onInput?.(value, event as InputEvent);
} else {
this.uncontrolledValue = value;
}
}

@action handleOnChange(event: Event): void {
const value = (event.target as HTMLInputElement).value;

if (this.isControlled) {
this.args.onChange?.(value, event as InputEvent);
} else {
this.uncontrolledValue = value;
}
}

this.inputRef.element?.focus();
triggerFormInputEvent(this.inputRef.element);
}

<template>
<FormControl
@size={{@size}}
@label={{@label}}
@isRequired={{@isRequired}}
@description={{@description}}
@errors={{@errors}}
@isInvalid={{@isInvalid}}
@class={{this.classes.base class=@classes.base}}
as |c|
>
<div class={{this.classes.innerContainer class=@classes.innerContainer}}>
{{#if (has-block "startContent")}}
<div
data-test-id="input-start-content"
class={{this.classes.startContent
class=@classes.startContent
startContentPointerEvents=(if
@startContentPointerEvents @startContentPointerEvents "auto"
)
}}
>
{{yield to="startContent"}}
</div>
{{/if}}
<input
{{this.inputRef.setup}}
{{on "input" this.handleOnInput}}
{{on "change" this.handleOnChange}}
id={{c.id}}
}}
data-component="input"
aria-invalid={{if c.isInvalid "true"}}
aria-describedby={{c.describedBy @description c.isInvalid}}
...attributes
/>
{{#if (or (has-block "endContent") this.isClearable)}}
<div
>
{{yield to="endContent"}}

{{#if this.isClearable}}
<CloseButton
/>
{{/if}}
</div>
{{/if}}
</div>
</FormControl>
</template>
}

export { Input, type InputSignature };
export default Input;
21 changes: 21 additions & 0 deletions tests/outputs/input.gts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 2.01
elapsed_seconds : 0.00317215919494629
n_files : 1
n_lines : 150
files_per_second : 315.242690717775
lines_per_second : 47286.4036076663
report_file : ../outputs/input.gts.yaml
'Glimmer TypeScript' :
nFiles: 1
blank: 17
comment: 24
code: 109
SUM:
blank: 17
comment: 24
code: 109
nFiles: 1

0 comments on commit 333d6bf

Please sign in to comment.