0.13.1 • Published 1 year ago

es2-postprocessor v0.13.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

es2-postprocessor

Post processor for legacy DHTML browsers.


Check for JavaScript Syntax Errors in IE <5.5 and Opera <8.0. Some syntax is rewritten. Otherwise, throws an SyntaxError.

Work around JavaScript engine bug in Gecko <=0.8.0.

Usage

const es2PostProcessor = require('es2-postprocessor');

sourceForLegacyBrowsers = es2PostProcessor(source, {minIEVersion: 5, minOperaVersion: 7, minGeckoVersion: 0.6});

gulp plugin

gulp.task('post_process_for_ie5_and_opera7',
    function(){
        return gulp.src('main.js')
                   .pipe(
                       require('es2-postprocessor').gulp({minIEVersion: 5, minOperaVersion: 7, minGeckoVersion: 0.6})
                   ).pipe(
                       gulp.dest('dist/js/legacy')
                   );
    }
);

gulp + es2-postprocessor + Google Closure Compiler

When formatting code with Google Closure Compiler.

gulp.task('post_process_for_ie5_and_opera7',
    function(){
        return gulp.src('main.js')
                   .pipe(
                       require('es2-postprocessor').gulp({minIEVersion: 5, minOperaVersion: 7, minGeckoVersion: 0.6})
                   .pipe(
                       require('google-closure-compiler').gulp()(
                           {
                               compilation_level : 'WHITESPACE_ONLY', // Prevent replacing labeled blocks.
                               formatting        : 'PRETTY_PRINT', // or 'SINGLE_QUOTES'
                               js_output_file    : 'main.es2.js'
                           }
                       )
                   ).pipe(
                       gulp.dest('dist/js/legacy')
                   );
    }
);

Options

PropertyDescriptionDefault value
minIEVersionSet to 4 if you want to fix syntax errors or warnings that occurs in IE4.5.5
minOperaVersionSet to 7 if you want to fix syntax errors or warnings that occurs in Opera 7.8.0
minGeckoVersionSet to 0.6 if you want to work around a bug that occurs in Gecko ~0.8.0.0.9
cloneSet to true if you want to compare the before and after code.false

ECMAScript3 Syntax Support Table

ExampleIEOperaGecko
instanceof operatorobj instanceof Object5(*1)
try statement, catch statement, throwtry{}catch(O_o){}5(*1)
in operator"length" in []5.5(*1)
Labeled Statement Blocka: {break a;}7.5(*2)
Object Literal with Numeric Property{1: 1}5.5(*3)
RegExp Literal/reg/
RegExp Literal with i g Flags/reg/ig
RegExp Literal with m Flag/reg/m5.5(*1)
  1. Just throw a Syntax Error
  2. Opera ~7.2x does not support Labeled Statement Block. Therefore, es2-postprocessor rewrite for workaround. If it is too complicated, throws an error.
  3. Rewrite for workaround.

Bugs in JavaScript implementation

ExampleIEOperaGecko
Object Literal with Empty String Property{"": ""}8(*1)
Function expression under parenthesesfunction c(){};(function(){c()})()0.8.1(*2)
  1. Throw a Syntax Error. Object Literal with Empty String Property is problematic in Opera 7.x.
  2. Gecko ~0.8.0 has a bug in Function expression under parentheses. Therefore, es2-postprocessor rewrite for workaround. It can be tested with the "Javascript 実装状況と深刻なバグ > IIFE".

Object Literal with Empty String Property in Opera ~7.2x.

obj = {"":"Good!"} //  Object Literal
obj[""] // == undefined
obj["0"] // == "Good!"

obj[""] = "Good!"; // Set empty string property
obj[""] // == "Good!"

It can be tested with the "Javascript 実装状況と深刻なバグ > Object Litearl".

Dynamic Rewriting escodegen

es2-postprocessor Rewrite line 814 of escodegen. This is being done dynamically.

result = parenthesize(generateVerbatimString(verbatim), Precedence.Sequence, precedence);
// ↓
result = generateVerbatimString(verbatim);

Links

  1. es2-postprocessorでOpera8未満、IE5.5未満でも動くJavaScriptを書く
  2. エイプリルフール企画などでレガシーブラウザ対応する場合に覚えておきたい最初期のDHTMLブラウザのJavaScriptの罠たちを回避する

License

es2-postprocessor is licensed under MIT License.

(C) 2022-2023 itozyun(outcloud.blogspot.com)

0.13.0

1 year ago

0.13.1

1 year ago

0.12.1

2 years ago

0.12.0

3 years ago

0.11.1

3 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago