Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internet Explorer 11: Object doesn't support property or method 'entries' #275

Closed
friedlhu opened this issue May 24, 2017 · 8 comments
Closed

Comments

@friedlhu
Copy link

friedlhu commented May 24, 2017

The following example does not work in Internet Explorer 11:

  Map<String, String> map = new HashMap<String, String>();
  map.put("one", "value1");
  map.put("two", "value2");
		
  for (String key : map.values()) {
	$("body").append($("<div/>").text(key));
  }

The code transpiles correctly to Javascript.
However, a problem occurs in bundle "j4ts-0.4.0-SNAPSHOT/bundle.js" (which I currently use):
this.entries = this.__parent.backingMap.entries();

The corresponding error message is:
Object doesn't support property or method 'entries'

The function Map.prototype.entries seems not to be supported in Internet Explorer:
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/entries
Is there any workaround or compatibility solution?

Problem occured with:
org.jsweet:j4ts:0.4.0-SNAPSHOT
org.jsweet:jsweet-core:6-SNAPSHOT
org.jsweet:jsweet-maven-plugin:2.0.0-SNAPSHOT
org.jsweet.candies:jquery:1.10.0-SNAPSHOT

Tested also with org.jsweet:j4ts:0.5.0-SNAPSHOT, but same problem. However, works perfectly in Chrome and Firefox.

Issue probably to move to https://github.com/j4ts/j4ts

@lgrignon
Copy link
Collaborator

lgrignon commented Jun 8, 2017

Thanks for reporting. Do you really need j4ts? Its usage is discouraged with JSweet 2 since the transpiler tries to transpile as much as it could of the Java API.

I tried with your specific code which works with JSweet 2 targetVersion ES5 without j4ts but maybe you require j4ts for other reasons.

Anyway if you plan to support IE11, you probably shouldn't try to use ES6 APIs (org.jsweet:jsweet-core:6-SNAPSHOT) since it is not supported in this browser:
https://kangax.github.io/compat-table/es6/

If you still want to use j4ts with JSweet 2, we should, indeed, move this issue to https://github.com/j4ts/j4ts ;)

@friedlhu
Copy link
Author

Thanks for your answer and the clarification!
Ok I am trying now to remove any dependencies to j4ts in my project.
However, doing so I figured out a problem which occurs at instantiation of type HashSet. For example, expression Set<Integer> d = new HashSet<Integer>() is transpiled to let d : Array<number> = <any>(<Array>new Array<number>()); which leads to a problem for tsc when compiling to javascript. The problem may be that in classorg.jsweet.transpiler.extension.RemoveJavaDependenciesAdapter, function substituteNewClass, there is no case statement for java.util.HashSet?

@lgrignon
Copy link
Collaborator

Well, this is weird because the TypeScript line you pasted is perfectly valid to me.
let d : Array<number> = <any>(<Array>new Array<number>());

Because there actually is a case statement for HashSet
https://github.com/cincheo/jsweet/blob/master/transpiler/src/main/java/org/jsweet/transpiler/extension/RemoveJavaDependenciesAdapter.java#L237

Did I miss something?

@friedlhu
Copy link
Author

Yes but not inside function substituteNewClass:
https://github.com/cincheo/jsweet/blob/master/transpiler/src/main/java/org/jsweet/transpiler/extension/RemoveJavaDependenciesAdapter.java#L1165
But maybe this is not necessary in this function?

For me, the transpiled code leads to a tsc problem (tsc version 2.1.6):

2017-06-11 18:05:34.034 INFO  JSweetTranspiler:1342 - quickstart/QuickStart.ts(10,44): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
2017-06-11 18:05:34.034 ERROR output:48 - generic type 'Array<T>' requires 1 type argument(s) at quickstart/QuickStart.java(13)

@lgrignon
Copy link
Collaborator

Nice one, I add the missing test case. Thanks for reporting!

@friedlhu
Copy link
Author

Great, thank you!

@lgrignon
Copy link
Collaborator

lgrignon commented Jun 11, 2017

It should be fixed through d5c67cc

Could you please test again and close if it fixes your problem?
Note: you may need to run mvn -U to force dependency update

Bye.

@friedlhu
Copy link
Author

Yes it works, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants