osscameroon / js-generator

Generates JavaScript from HTML
https://osscameroon.github.io/js-generator/
MIT License
19 stars 14 forks source link

Points to discuss on saturday 29 April 2023 #236

Open FanJups opened 1 year ago

FanJups commented 1 year ago

1- How to run only one test ?

2- Meaning of this code in ApiTest ?

        public Match(final String[] lines) {
            super("jsjenerator-matcher");
            this.lines = lines;
        }

3- What happens if we have 2000 divs ? The program goes from 0 to 999 as you can see 03d. Should we not start at 001 instead of 000 ? https://github.com/osscameroon/js-generator/issues/239 https://github.com/osscameroon/js-generator/issues/240

public class TypeBasedVariableNameStrategy implements VariableNameStrategy {
    private final Map<String, AtomicLong> counters = new HashMap<>();

    @Override
    public String nextName(@NonNull String type) {
        // NOTE: issue#145 careful with custom element about casing and dash, not to translate in JavaScript identifiers
        var identifier = type;
        final var HAS_DASH = type.contains("-");
        final var IS_ROOT = "targetElement".equals(type);
        final var HAS_UPPER_CASE = !type.chars()
                .allMatch(character -> Character.toLowerCase(character) == character);

        if (!IS_ROOT) {
            identifier = HAS_UPPER_CASE ? type.toLowerCase() : identifier;
            identifier = HAS_DASH
                    ? type.replaceAll("-", "_").replaceAll("_+", "_") : identifier;

            if (HAS_DASH || HAS_UPPER_CASE) {
                identifier = "custom_%s".formatted(identifier);
            }
        }

        return format("%s_%03d", identifier, counters.computeIfAbsent(type, __ -> new AtomicLong()).getAndIncrement());
    }
}
FanJups commented 1 year ago

https://github.com/osscameroon/js-generator/issues/235

FanJups commented 1 year ago

https://github.com/osscameroon/js-generator/issues/238