Typescript Quickstart Tutorial - typescript2.0

I am working with Visual Studio 2015, ASP.NET Core
When I walkthrough the Typescript Tutorial version 2.0.6.0 I have a problem with the function sayHello not producing the correct output.
function sayHello() {
const compiler = (document.getElementById("compiler") as HTMLInputElement).value;
const framework = (document.getElementById("framework") as HTMLInputElement).value;
return "Hello from ${compiler} and ${framework}!";
}
When I edit a textbox I see the following output:
Hello from ${compiler} and ${framework}!
The variables are not replaced as would be expected.
Does anyone have any idea what could be wrong here?

You have to use template strings surrounded by backtick/backquote (`) characters to embed expressions within.
return `Hello from ${compiler} and ${framework}!`;

Related

VB.NET equivalent of Func

I have a C# statement
solidGauge1.LabelFormatter = val => val.ToString("P");
I want the VB.NET equivalent. Telerik code converter gives
"solidGauge1.LabelFormatter = Function(val) val.ToString("P")"
This is not correct since it seems to be ignored. The C# statment works in a C# project. The usage/source of this is lvCharts Gauge control
Try this
solidGauge1.LabelFormatter = Val.ToString("P")

Drag-and-drop ES6 imports in Visual Studio for TypeScript

Currently in Web-Essentials (for Visual Studio 2015), if a .ts file from the Solution Explorer is dragged and dropped into an open .ts file, a reference path is automatically inserted at the top:
/// <reference path="../playback/key.ts" />
This is fine when a project is being developed using internal modules (namespaces), but is virtually useless when going external. How could I make it so that an ES6 import statement is generated instead? That would be awesome. Such as:
import {} from "../playback/key";
It turns out what we are seeing is a built-in feature of Web-Essentials. I've filed a feature-request to get this available, hopefully in the near future.
In the meantime, the following Visual Commander automation snippet can replace all references to ES6 imports:
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;
public class C : VisualCommanderExt.ICommand
{
// Called by Visual Commander extension.
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
TextDocument doc = (TextDocument)(DTE.ActiveDocument.Object("TextDocument"));
var p = doc.StartPoint.CreateEditPoint();
string s = p.GetText(doc.EndPoint);
p.ReplaceText(doc.EndPoint, this.ReplaceReferences(s), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
}
// Converts "reference" syntax to "ES6 import" syntax.
private string ReplaceReferences(string text)
{
string pattern = "\\/\\/\\/ *<reference *path *= *\"([^\"]*)(?:\\.ts)\" *\\/>";
var regex = new Regex(pattern);
var matches = Regex.Matches(text, pattern);
return Regex.Replace(text, pattern, "import {} from \"./$1\";");
}
}
The regex used to perform this replace is (without the double backslashes, more readable):
\/\/\/ *<reference *path *= *"([^"]*)(?:\.ts)" *\/>
This snippet will effectively convert all reference comments to ES6 imports in the currently active document, very useful.
Known issues:
a comment containing a reference tag is not recognized by Visual Studio if it is preceded by other text in the corresponding line, but it is still replaced by this snippet
additional text after a reference tag is valid, but after replace will cause syntax errors, since it is no longer a comment.
(Neither of these issues are relevant if the snippet is used on reference tags generated by Web-Essentials when a .ts file is drag-and-dropped.)

Code Editor with intellisense for ANTLR4

Looking for sample for building ANTLR4 grammar based Code Editor with intellisense. SharpDevelop provides all Code Editor features, however if we need to provide the intellisense and Code Completion details, then we need to write own parser.
Need sample where ANTLR4, SharpDevelop is used for building the Code Editor for custom language.
Thanks.
I could get the expected Tokens from ANTLR4 using GetExpectedTokensWithinRule API in the Listener and converting them to tokens.
pseudo code looks like this
public class MyGrammarListener : MyGrammarBaseListener
{
public MyGrammarListener(MyGrammarParser parser)
{
this.Parser = parser;
}
public override void EnterXXXXX(XXXXX_Context context)
{
IntervalSet set = Parser.GetExpectedTokensWithinCurrentRule();
base.EnterXXXXX(context);
foreach (int token in set.ToIntegerList())
{
// Returns the expected tokens.
string data = Parser.Vocabulary.GetLiteralName(token);
}
}
}
I have used Jide CodeEditor with antlr4, it seems to be working OK but took some time to get it together. I generate the errors and keywords for highlighting from the parser. I use listeners for parsing etc. and a visitor for executing the language. Not familiar with SharpDevelop

ASP.NET Minification removes javascript function name in some scenarios

Good Day,
I am using default ASP.NET 4.5.1 bundling. All scripts are minified as expected apart of the following code:
var events = [
function Create() {
},
function Delete() {
}
];
it was minified to
var t = [function(){},function(){}];
Why does ASP.NET optimization remove function names in above scenario and how can I avoid it?
Part of it is because you have an array of functions and they are accessed via an index like so:
events[0]();
events[1]();
The name of each function in the array is irrelevant so the minifier probably realizes this and removes those names.
As for why it changed the variable name "events" to "t", variable names are shortened to 1 character according this MSDN page.

Translation of Zend_Validation in ZF2

I have a strange Problem in Zend Framework 2. I've used the Zend Skeleton Application (https://github.com/zendframework/ZendSkeletonApplication) and added PhlyContact as Vendor Module (https://github.com/weierophinney/PhlyContact). I changed the Translation-Type to PhpArray so that i can use the Zend_Validate.php located in the resources-dir of the ZF2-Dist.
Everything translates EXCEPT the validation Messages :/ So i guess i am missing something:
I must pass the Translator to Zend_Validate (but how and where?)
The Translation should use a Text-Domain, but doesn't
When i remember right in ZF1 you had to set the Translator to default to pass it to Zend_Validate. Any Ideas on that !?
have a look at these methods
\Zend\Validator\AbstractValidator::setDefaultTranslator();
\Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain();
You can even do this with only one line (2nd parameter is text domain):
AbstractValidator::setDefaultTranslator($translator, 'default');
Example within Module.php:
use Zend\Validator\AbstractValidator;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$translator = ....
AbstractValidator::setDefaultTranslator($translator, 'default');
}
}