I'm trying to use iojs with koa, what works well. But Webstorm doesn't accept the generator functions as valid.
/** gets marked as syntactically invalid code */
app.use(function *() {
this.body = 'Hello World';
});
My actual version is Webstorm 9.
Is there maybe a workaround? I couldn't find a matching option for it.
Go to the Preferences > Languages & Frameworks > JavaScript and chose ECMAScript 6 for JavaScript language version.
Related
Created a new project using the aurelia-cli - SystemJS bundler option.
installed htmlparser2 module from npm which has buffer.js as a dependency.
getting the following error when attempting to import htmlparser2:
bluebird.core.js:3434 Error: global is not defined
Evaluating http://localhost:9000/buffer/index
upon inspecting vendor-bundle -> this is the line that creates the error:
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
found a similar issue with angualar-cli where the solution was to manually turn on node global
Node global is turned off. It works fine if I manually turn it on again.
The question is how to do this using the aurelia-cli? Any suggestions?
larger code snippet from vendor-bundle
define('buffer/index',['require','exports','module','base64-js','ieee754','isarray'],function (require, exports, module) {/*!
* The buffer module from node.js, for the browser.
*
* #author Feross Aboukhadijeh <feross#feross.org> <http://feross.org>
* #license MIT
*/
/* eslint-disable no-proto */
'use strict'
var base64 = require('base64-js')
var ieee754 = require('ieee754')
var isArray = require('isarray')
exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
I believe you are using cli built-in bundler (I wrote it), not webpack.
Yes, nodejs global var global is currently not supported. Also nodejs global vars process and Buffer have similar issues.
The cli doc has a patch to support process and Buffer.
import process from 'process';
window.process = process;
import {Buffer} from 'buffer';
window.Buffer = Buffer;
You can try to add one more patch for global.
window.global = window;
Ok why cli has the issue
cli's tracing algorithm uses rjs (requirejs optimizer) parser, it's bit old, does not detect global vars (technically it does not do variable scope analysis).
I have another WIP bundler called dumber which solved the limitation with a new parser which detects global vars. It automatically patch nodejs global vars at module level based on need.
In long term, we will drop the code for cli built-in bundler, then wrap dumber and make it backward compatible.
i use below command to init a project
react-native init MyAwesomeProject --template typescript
and create a add.tsx file
'use strict';
// this function return string, but it should return number
function add(left: number, right: number): number{
return left + right + 'test';
}
console.log(add('it is a wrong param', 1));
export default add;
add.tsx is imported by App.js. when i run this project, no warning or error is printed, i don't know why
Running react-native init MyAwesomeProject --template typescript sets up a project that can accept typescript code, however it very confusingly doesn't actually set up type checking. Under the hood this is because it sets up Babel (a javscript compiler) which simply strips the TypeScript type annotations. It doesn't actually set up TypeScript itself which would do the actual type checking.
Without seeing your exact project I can't know exactly what you need to fix, but I would suggest following the steps on https://facebook.github.io/react-native/blog/2018/05/07/using-typescript-with-react-native Specifically where it mentions installing typescript ("Adding TypeScript" section), then add a tsconfig.json with {"compilerOptions":{"noEmit": true}}, and then finally you should be able to run ./node_modules/.bin/tsc to actually type check your code.
System
OSX v10.13.4 / Elixir v1.6.5 / OTP 19 / Phoenix 1.3.2 / Wallaby 0.19.2 / PhantomJS 2.1
Issue
The following code works in testing
execute_script(session, "localStorage.setItem('test', 'foo'); return localStorage.getItem('test');")
However, if I call the exact same methods which are in a function called get_test() inside app.js of my Phoenix App
function get_test() {
localStorage.setItem('test', 'foo');
return localStorage.getItem('test');
}
window.get_test = get_test
And run the following in my test suite
execute_script(session, "return get_test();")
I get {:error, :obscured}
I have tried with selenium on the same code and it works. However, for some reason, with PhantomJS it does not seem to find functions that have been created by ourselves.
Am I missing something? I did notice in the tests for execute_script in wallaby there are no tests that call specifically created functions.
https://github.com/keathley/wallaby/blob/master/integration_test/cases/browser/execute_script_test.exs
A similar test
https://github.com/keathley/wallaby/blob/master/integration_test/cases/browser/local_storage_test.exs
of which I added the following to the local_storage_test to verify I was not going nuts
#function_script """
function get_tester() {
localStorage.setItem('tester', 'foo');
return localStorage.getItem('tester');
}
return get_tester();
"""
session
|> visit("index.html")
|> execute_script(#function_script, fn(value) -> send self(), {:callback, value} end)
assert_received {:callback, "foo"}
and it passed. This is clearly something wrong with my app. Or Phantom config perhaps.
UPDATE:
Although not mentioned directly - I have narrowed this down to libsodim not loading properly with phantomjs. Back to basics on the debugging. Nothing wrong with the JS written. On a positive note, I now have a whole library of tests which is cool and some cool tools for testing.
This line of code is correct and it's working well, but it is causes a lint message: ") expected". Are there settings changes I could make to prevent this?
state = {selected: (new Map(): Map<string, boolean>)};
Looks like you are using Flow - this is the only JavaScript dialect that supports static typing (type annotations) + class fields. Please make sure to set JavaScript Language version accordingly - choose Flow in Settings | Languages & Frameworks | JavaScript
I've searched much time about IntelliJ IDEA 12 and the xdebug.file_link_format configuration value.
I found nothing which works...
Using protocols like "idea", "intellij", "txmt", or other protocols doesn't work.
I found nothing about a plugin which register the IntelliJ protocol...
Is it possible to use the xdebug file links with IntelliJ IDEA or PhpStorm?
Yes and No.
No -- there is no proper built-in support for this. Watch this ticket for details: http://youtrack.jetbrains.com/issue/IDEA-65879
Yes -- you may find some workaround, at very least the aforementioned ticket has recipes for Mac OS (using AppleScript) or via Remote Call etc.
Update: as of PhpStorm 8 you may use:
xdebug.file_link_format = "phpstorm://open?file=%f&line=%l"
Not out of the box, but it is possible to get the links to work. I have this working with Windows 7, Firefox and PhpStorm 10 - in this example, I'm using the protocol phpstorm://, but this will work regardless of the name.
create a custom protocol handler: Any executable will do, here I have modified a WScript from https://pla.nette.org/en/how-open-files-in-ide-from-debugger . Save as run-editor.js :
// note: edit the path, with backslashes escaped
var editor = '"c:\\Program Files (x86)\\JetBrains\\PhpStorm 143.434\\bin\\PhpStorm.exe" nosplash --line %line% "%file%"';
var url = WScript.Arguments(0);
var match = /^phpstorm:\/\/open\/\?file=(.+)&line=(\d+)$/.exec(url);
if (match) {
var file = decodeURIComponent(match[1]).replace(/\+/g, ' ');
var command = editor.replace(/%line%/g, match[2]).replace(/%file%/g, file);
var shell = new ActiveXObject("WScript.Shell");
shell.Exec(command.replace(/\\/g, '\\\\'));
}
create the protocol in registry: create the following as editor.reg and import to Registry. Note that you again need to double-escape the path to the above file, and set it to wherever yours is saved:
REGEDIT4
[HKEY_CLASSES_ROOT\phpstorm]
#="URL:phpstorm Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\phpstorm\shell\open\command]
#="wscript \"C:\\path\\to\\run-editor.js\" \"%1\""
enable the protocol in Firefox:
in about:config, create a "logical value" named
network.protocol-handler.expose.phpstorm and set it to false
open one such link in Firefox, e.g. phpstorm://open?file=somefile.html&line=123 - it should open in PhpStorm.
Per the comment from #gapple, this will make Xdebug link to the file/link in PhpStorm:
xdebug.file_link_format = "phpstorm://open?file=%f&line=%l"
I tested this in PhpStorm 10 on Mac and it works great.
You need to ad to the php.ini file in the [xdebug] section the following line:
xdebug.file_link_format = "phpstorm://open?file=%f&line=%l"
Then restart your web server (Apache for me on Mac)
The REST API is probably the best option now:
http://localhost:63342/api/file%f:%l
Wrapping in a javascript protocol and AJAX request allows the permission approval to be saved so you don't have to approve every time you click:
javascript: var r = new XMLHttpRequest; r.open('get', 'http://localhost:63342/api/file%f:%l');r.send()
API specs:
https://www.develar.org/idea-rest-api/